在angularJS中设置不同的子路径

时间:2013-10-03 16:21:27

标签: javascript angularjs angularjs-directive

我有两个routes路由到一个名为controller的{​​{1}}。

一个使用$ routeParams而一个没有它。

storyboard

但是当我致电 $routeProvider.when('/storyboard/:cureId', { templateUrl: '/partials/storyboard.html', controller: 'Storyboard', access: access.parent, area: 'storyboard' }); $routeProvider.when('/storyboard/addTarget', { templateUrl:'/partials/storyboard_new_target.html', controller: 'Storyboard', access: access.supervisor, area: 'storyboard' }); $routeProvider.when('/storyboard/addSession', { templateUrl:'/partials/storyboard_new_session.html', controller: 'Storyboard', access: access.parent, area: 'storyboard' }); $routeProvider.otherwise({redirectTo:'/404'}); 时,Angular会将我重定向到/storyboard/addSession,并使用$ routeParams获取/storyboard/addSession

1 个答案:

答案 0 :(得分:3)

ngRoute根据注册顺序处理路由。因此/storyboard/addSession应与第一条路线匹配(即/storyboard/:cureId)。我想你希望它匹配示例中的第三条路线。只需更新订单,以便最后注册参数化路线。

$routeProvider.when('/storyboard/addTarget',
{
    templateUrl:'/partials/storyboard_new_target.html',
    controller: 'Storyboard',
    access: access.supervisor,
    area:     'storyboard'
});   
$routeProvider.when('/storyboard/addSession',
{
    templateUrl:'/partials/storyboard_new_session.html',
    controller: 'Storyboard',
    access: access.parent,
    area:     'storyboard'
});     
$routeProvider.when('/storyboard/:cureId',
{
    templateUrl:    '/partials/storyboard.html',
    controller: 'Storyboard',
    access: access.parent,
    area:     'storyboard'
});