2 回答

TA貢獻1874條經(jīng)驗 獲得超12個贊
有針對這種情況的解決方案。我們將使用1)一種ui-router本機功能和2)一種配置設(shè)置。這里可以看到一個有效的例子。
1)ui路由器狀態(tài)定義的本機功能是:
該url是沒有必要的??梢远x狀態(tài)而無需在位置上表示。
2)配置設(shè)置為:
otherwise()對于無效的路由,該參數(shù)不必是具有默認url的字符串,但也可以是一個函數(shù)(引用):
路徑字符串| 函數(shù)要重定向到的URL路徑或返回URL路徑的函數(shù)規(guī)則。函數(shù)版本傳遞兩個參數(shù):$ injector和$ location
解決方案:兩者結(jié)合。我們將state 沒有 url and custom otherwise:
$stateProvider
.state('404', {
// no url defined
template: '<div>error</div>',
})
$urlRouterProvider.otherwise(function($injector, $location){
var state = $injector.get('$state');
state.go('404');
return $location.path();
});

TA貢獻1806條經(jīng)驗 獲得超8個贊
截至ui-router#0.2.15您可以使用$state.go()和發(fā)送選項不更新位置:
$urlRouterProvider.otherwise(function($injector) {
var $state = $injector.get('$state');
$state.go('404', null, {
location: false
});
});
- 2 回答
- 0 關(guān)注
- 773 瀏覽
添加回答
舉報