我创建了我的第一个Ember应用程序,并且有一个路由问题。我有一个模板,显示这种类型的路线模型:Ember路由器问题
this.resource('collection', {path: '/collection/:collection_id'});
当网址中有一个id时,页面重新加载。但我有一个情况下基于用户互动时collection_id不再可用,则网址如下:
http://localhost:8080/discover/index.html#/collection/
但是,如果我重新加载这个页面,我得到一个错误:
'Assertion failed: The URL '/collection/' did not match any routes in your application'
我会想解决这个问题,我想如果我能捕捉到这种状态,并为它做这样的事情:
this.transitionTo('home');
这将使意义上我的应用程序。问题是我该如何做到这一点。如果有人有一个想法如何做到这一点,你的帮助是非常感谢。
我的路由器是这样的:
App.Router.map(function(){
this.resource('home', {path: '/'});
this.resource('admin', function(){
this.route('user');
this.route('storage');
});
this.resource('help');
this.resource('collection', {path: '/collection/:collection_id'});
});
所以只有这个“this.resource('collection',{path:'/ collection /:collection_id'});”会导致这个问题? – user2917629
Ember只是不知道如何处理URL'/ collection',因为您只为URL'/ collection /:collection_id'创建了一个。你可以添加'this.resource('collectionRoot',{path:'/ collection'});'并创建一个对应的App.CollectionRootRoute来处理它(命名CollectionRoot是完全任意的)。 – Poindexter
太棒了!这工作就像一个魅力 - 谢谢,谢谢,谢谢! – user2917629