Javascript 有条件的;否则";角度布线

Javascript 有条件的;否则";角度布线,javascript,angularjs,angular-ui-router,Javascript,Angularjs,Angular Ui Router,我熟悉angular中的“$urlRouterProvider.otherwise(“{route here}”)”语法,以便在angular UI路由器中用作catch all 我想知道的是,当路由输入错误时,有没有一种方法可以基于父状态执行有条件的“否则”路由 例如,假设我有以下配置: $stateProvider .state('core', {configuration here}) .state('core.page1', {configuration here...}) .state

我熟悉angular中的
“$urlRouterProvider.otherwise(“{route here}”)”
语法,以便在angular UI路由器中用作catch all

我想知道的是,当路由输入错误时,有没有一种方法可以基于父状态执行有条件的“否则”路由

例如,假设我有以下配置:

$stateProvider
.state('core', {configuration here})
.state('core.page1', {configuration here...})
.state('dashboard', {configuration here})
.state('dashboard.page1', {configuration here})

$urlRouterProvider.otherwise('/core/page1');
我希望发生的是,任何时候输入的路由都具有
“/core/{route here}”

如果它与任何当前状态不匹配,则要路由回“/core/page1”
任何时候,只要输入的路由具有与当前状态不匹配的
“/dashboard/{route here}”
,就可以路由回
“/dashboard/page1”

有没有人有这样做的经验,或者有没有人知道我如何才能做到这一点?Angular中是否有允许这种行为的内置功能

提前谢谢

如图所示

否则()
不必是字符串(url)。。。它可能是一个聪明的决策者:

$urlRouterProvider.otherwise(function($injector, $location){
   var state = $injector.get('$state');
   if(....)
     state.go('core');
   else(...)
     state.go('dashboard');
   ...
   return $location.path();
});
文件:

定义请求无效路由时使用的路径

string-要重定向到的url路径或返回url路径的函数规则。
函数版本传递了两个参数:$injector和$location services,并且必须返回url字符串


哇!感谢您的快速响应。这和我要找的一模一样!仅供参考-您列出的链接($urlRouterProvider.OR(规则))不起作用。您是对的。。。谢谢我修复了链接以直接访问文档;)