【问题标题】:Ember Fastboot redirect to external URLEmber Fastboot 重定向到外部 URL
【发布时间】:2019-12-16 23:33:06
【问题描述】:

我希望从 Fastboot 中的 Ember 路由内 301 重定向到外部 URL(基于 model() 返回的数据)。

一种解决方案是从 Ember 中访问 Express.js 响应对象,因此我可以调用类似:

res.redirect(301, 'http://external-domain.com')?

但是,我不完全确定如何从 Ember 中访问 res 对象。 Fastboot 暴露了一个 response 对象,但它与 Express res 不同。

【问题讨论】:

    标签: express ember.js ember.js-fastboot


    【解决方案1】:

    以下代码将在 Fastboot 和浏览器中重定向:

    if (this.get('fastboot.isFastBoot')) {
      this.get('fastboot.response.headers').set('location', 'http://google.com');
      this.set('fastboot.response.statusCode', 302);
    } else {
      window.location.replaceWith('http://google.com');
    }
    

    【讨论】:

      猜你喜欢
      • 2017-12-11
      • 2012-01-10
      • 2012-08-02
      • 1970-01-01
      • 1970-01-01
      • 2019-04-03
      • 2019-10-23
      • 2015-02-14
      • 1970-01-01
      相关资源
      最近更新 更多