i0n*_*i0n 9 ember.js ember-router
我正在使用Ember.js并且我想创建一个catch all route,以便在用户导航到与资源不匹配的URL时将用户发送回应用程序的根目录.(我正在使用历史API)我已经实现了这样:
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({
});
Run Code Online (Sandbox Code Playgroud)
我的问题是:我可以定义一个单一的捕获所有路径,它将匹配任何未解析为资源的路径,而不管路径中的段数是多少?
我使用的是Ember.VERSION:1.0.0-rc.1
Shi*_*nko 22
经过一番摆弄后,我想我找到了一个解决方案:*:似乎就是这样做的
this.route('catchAll', { path: '*:' });
Run Code Online (Sandbox Code Playgroud)
我设置这个小提琴来演示它是如何工作的.