8
我正在使用Ember.js,并且我想创建一个捕获所有路由,以便将用户返回到应用程序的根目录,如果它们导航到的URL不匹配资源。 (我用的是历史API)我已经实现了这个像这样:在ember.js中定义多段式捕获所有路由
App.Router.map(function() {
this.resource('things', function() {
this.resource('thing', {path:':thing_id'});
});
this.route('catchAll', { path: ':*' });
this.route('catchAll', { path: ':*/:*' });
this.route('catchAll', { path: ':*/:*/:*' });
});
App.Router.reopen({
location: 'history'
});
App.CatchAllRoute = Ember.Route.extend({
redirect: function() {
this.transitionTo('index');
}
});
App.IndexRoute = Ember.Route.extend({
});
我的问题是:我可以定义一个包罗万象的路线,将符合尚未解决的资源,不论数量的任何路径段中的路径?
我使用Ember.VERSION:1.0.0-RC.1
Ups,发现复制粘贴错误,代码已更新。 – 2013-02-27 09:05:41
完美!谢谢! – i0n 2013-02-27 11:28:33
这是正确的,或多或少,但有点混乱。 ':'是你给这个捕获所有部分的名字。而不是'* wildcardurl'或类似的。就像你在模型设置中用参数做事一样。 – 2014-02-20 13:49:25