我是AngularJs的新手,我正在学习一些教程以了解一些内容。
现在我正在处理路线。我的配置类似:
$routeProvider
.when('/',
{
controller: 'Controller1',
templateUrl: 'View1.html'
})
.when('/one',
{
controller: 'Controller1',
templateUrl: 'View1.html'
})
.when('/two',
{
controller: 'Controller2',
templateUrl: 'View2.html'
})
.otherwise({redirectTo: '/'});
现在我想知道,是否有可能将前两个.when
合并为一个条件?
我试过像.when(['/', '/one'], ...
这样的东西,但它不起作用。
有没有办法做到这一点?
答案 0 :(得分:1)
您可以使用:
.when('/one',
{
redirectTo: '/';
})
或者在这种情况下,省略when('/ one'),因为想要的行为与otherwise()相同。
答案 1 :(得分:0)
不可能使用路由数组作为'when'的参数。更多信息:
http://docs.angularjs.org/api/ngRoute。$ routeProvider
如此简短的回答,不,我不知道你怎么能这样做。