Backbone.js路由器 - 使用splat的路由也调用没有splat的路由

时间:2012-07-03 08:14:21

标签: backbone.js backbone-routing

我有一个使用以下路由设置的backbone.js路由器:

routes : {
  'a-route' : 'goToRoute',
  'a-route/*splat' : 'goToRoute'
}

goToRoute : function(splat){
if(!splat) {
  // do this
} else {
  // do that with splat
}

我做的时候

router.navigate('a-route', {trigger : true});

一切正常。但是当我做的时候

router.navigate('a-route/more', {trigger : true});

路由器触发两次:首先使用splat等于'undefined',然后第二次使用splat等于'more'。

如果我注释掉路线'a-route':'goToRoute',那么一切都可以正常使用router.navigate('a-route / more')......但是我需要两条路线 - 有和没有啪的一声。

根据文档,我认为我的设置正确,任何想法?

1 个答案:

答案 0 :(得分:0)

您不需要使用*,您必须使用:在您的情况下。

routes : {
  'a-route' : 'goToRoute',
  'a-route/:splat' : 'goToRoute'
}
相关问题