定义一个多分段捕获所有路由在ember.js [英] Defining a multi segmented catch all route in ember.js
问题描述
App.Router.map(function(){
this.resource('things',function(){
this.resource('thing',{path:':thing_id'});
});
这个。 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
经过一些琐事之后,我想我已经找到了一个解决方案: *:
,如
this.route('catchAll',{path:'*:'} );
我设置了这个小提琴来演示它是如何工作的。
I am using Ember.js and I would like to create a catch all route to send the user back to the root of the application if they navigate to a URL that does not match a resource. (I am using the history API) I have implemented this like so:
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({
});
My question is: Can I define a single catch all route that will match any path that has not resolved to a resource irrespective of the number of segments in the path?
I am using Ember.VERSION : 1.0.0-rc.1
After some fiddling i think I've found a solution: the *:
seems to do the trick, like
this.route('catchAll', { path: '*:' });
I set up this fiddle to demonstrate how it works.
这篇关于定义一个多分段捕获所有路由在ember.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!