2013-09-30 54 views
0

我是AngularJs的新手,我正在学习一些教程来学习一些东西。如何配置不同的路径到同一个'controller'和'templateUrl'?

现在我正在处理路线。我的配置是类似的东西:

$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'], ...但它不起作用。

有没有办法做到这一点?

回答

1

你可以使用:

.when('/one', 
{ 
    redirectTo: '/'; 
}) 

或在这种情况下,离开了的时候(“/一个”),因为想要的行为是一样的,否则()。

相关问题