我正在使用 AngularJS和 ui-router在我的 app.js
中。我有以下行:
$urlRouterProvider.otherwise('/');
然而,我不希望它把用户发送到一个 URL,而是而是 一个状态:
.state('404',
{
views: {
'body': {
templateUrl: 'partials/404.html',
}
}
});
通常我会这样做:
$state.go('404');
如何为 otherwise 方法执行此操作?
注意:我的 404 状态没有 URL,所以基本上它保留了用户输入或访问过的 URL,只是更改了模板。
最佳答案
我想你是用这段代码实现的
$urlRouterProvider.otherwise(function($injector, $location){
$injector.invoke(['$state', function($state) {
$state.go('404');
}]);
});
关于javascript - AngularJS ui-router 否则声明而不是 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26181141/