2 回答

TA貢獻1874條經驗 獲得超12個贊
有針對這種情況的解決方案。我們將使用1)一種ui-router本機功能和2)一種配置設置。這里可以看到一個有效的例子。
1)ui路由器狀態定義的本機功能是:
該url是沒有必要的??梢远x狀態而無需在位置上表示。
2)配置設置為:
otherwise()對于無效的路由,該參數不必是具有默認url的字符串,但也可以是一個函數(引用):
路徑字符串| 函數要重定向到的URL路徑或返回URL路徑的函數規則。函數版本傳遞兩個參數:$ injector和$ location
解決方案:兩者結合。我們將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條經驗 獲得超8個贊
截至ui-router#0.2.15您可以使用$state.go()和發送選項不更新位置:
$urlRouterProvider.otherwise(function($injector) {
var $state = $injector.get('$state');
$state.go('404', null, {
location: false
});
});
- 2 回答
- 0 關注
- 777 瀏覽
添加回答
舉報