Defining a multi segmented catch all route in ember.js

与世无争的帅哥 提交于 2019-12-21 09:23:07

问题


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


回答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.



来源:https://stackoverflow.com/questions/15068558/defining-a-multi-segmented-catch-all-route-in-ember-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!