2013-09-30 55 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: '/'; 
}) 

或在這種情況下,離開了的時候(「/一個」),因爲想要的行爲是一樣的,否則()。

相關問題