如何让 $urlRouterProvider.otherwise 重定向到状态而不是路径?
How to get $urlRouterProvider.otherwise to redirect to a state instead of a path?
我想重定向到一个状态而不是路径,不太清楚该怎么做。
有类似问答:
How not to change url when show 404 error page with ui-router
我们可以得到注射器并要求 $state
$urlRouterProvider.otherwise(function($injector, $location){
var state = $injector.get('$state');
state.go('404');
return $location.path();
});
see that 一个工作的 plunker
.otherwise() 不一定是字符串(url)或状态,它可能是一个聪明的决策者:
您可以通过以下代码得到想要的结果:
$urlRouterProvider.otherwise(function($injector, $location){
$injector.invoke(['$state', function($state) {
$state.go('yourState');
}]);
});
我想重定向到一个状态而不是路径,不太清楚该怎么做。
有类似问答:
How not to change url when show 404 error page with ui-router
我们可以得到注射器并要求 $state
$urlRouterProvider.otherwise(function($injector, $location){
var state = $injector.get('$state');
state.go('404');
return $location.path();
});
see that 一个工作的 plunker
.otherwise() 不一定是字符串(url)或状态,它可能是一个聪明的决策者:
您可以通过以下代码得到想要的结果:
$urlRouterProvider.otherwise(function($injector, $location){
$injector.invoke(['$state', function($state) {
$state.go('yourState');
}]);
});