2015-10-13 140 views
0

我設置的初始狀態先進入應用程序用一個簡單的條件時,(我完全瞭解它也可以防止深層鏈接..這就是OK)。是否有可能使用ui路由器設置初始狀態和其他狀態?

.run(function($state, browserFactory) { 

    if (browserFactory.isSupported()) { 
     $state.go('browser-unsupported'); 
    } else { 
     $state.go('welcome'); 
    } 
} 

這工作正常。

但是,如果我設置一個otherwise規則將始終遵循這一規則。例如,如果我設置

.config(function($urlRouterProvider) { 
    $urlRouterProvider.otherwise('/welcome'); 
} 

它總是會在/welcome結束。

有沒有辦法解決這個問題,或者根據條件擁有otherwise規則來設置初始路由?

+0

的可能的複製[否則上StateProvider](http://stackoverflow.com/questions/16793724/otherwise-on-stateprovider) – estus

回答

0

我能想到的唯一的解決辦法就是做這個邏輯在主控制器所以,即使你重定向到歡迎,它會通過if語句後更改爲所需的路徑。

基本上你app.run你不應該把得多的代碼。