AngularJS ui-router 否则要声明而不是 url? [英] AngularJS ui-router otherwise to state instead of url?
本文介绍了AngularJS ui-router 否则要声明而不是 url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 AngularJS 和 ui-router 和我的 app.js
.我有以下几行:
I am using AngularJS and ui-router and in my app.js
. I have the following line:
$urlRouterProvider.otherwise('/');
但是我不希望它把用户发送到一个 URL 而是而是 到一个状态:
.state('404',
{
views: {
'body': {
templateUrl: 'partials/404.html',
}
}
});
通常我会这样做:
$state.go('404');
对于其他方法,我该如何做到这一点?
How can I do this for the otherwise method?
注意:我的 404 状态没有 URL,所以基本上它保留了用户输入或访问过的 URL,只是更改了模板.
推荐答案
我认为你用这段代码实现了
I think you achieved that with this code
$urlRouterProvider.otherwise(function($injector, $location){
$injector.invoke(['$state', function($state) {
$state.go('404');
}]);
});
这篇关于AngularJS ui-router 否则要声明而不是 url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文