Ember.js路由可以重定向到外部URL吗?

Chr*_*ris 16 ember.js ember-router

如果我想在名为example1.com的Ember.js网站上有一个转发到example2.com上的URL的URL,我该怎么做呢.我可以创建一个example1.com的路由,它将执行转发到example2.com - 也许在beforeModel钩子中?

cho*_*per 17

只需使用常规<a>:

<a href="example2.com">Route to Example 2</a>
Run Code Online (Sandbox Code Playgroud)

如果您希望在用户直接在地址栏中输入URL时将其转发,则需要在服务器中进行重定向.这与Ember没有任何关系.

或者你可以使用

App.YourRoute = Ember.Route.extend({
  redirect: function() {
     window.location.replace("http://stackoverflow.com");
  }
});
Run Code Online (Sandbox Code Playgroud)

beforeModel(或任何其他)钩也应该工作.


Jak*_*oby 12

在任何钩子中,使用:

window.location.replace("example2.com");
Run Code Online (Sandbox Code Playgroud)