我使用 AngularJS 和 UI -router 并在我的 app.js
。我有以下行:
I am using AngularJS and ui-router and in my app.js
. I have the following line:
$urlRouterProvider.otherwise('/');
然而我不希望它给用户发送到网址,但而不是的以状态
.state('404',
{
views: {
'body': {
templateUrl: 'partials/404.html',
}
}
});
一般情况下我只是这样做:
Normally I would just do this:
$state.go('404');
我怎么能做到这一点的,否则的方法?
How can I do this for the otherwise method?
的注:我的404的状态并没有一个URL,所以基本上保留了用户进入或访问,只是改变了模板中的网址的
我觉得你实现了这个code
I think you achieved that with this code
$urlRouterProvider.otherwise(function($injector, $location){
$injector.invoke(['$state', function($state) {
$state.go('404');
}]);
});