我有一个动态路由定义为:
$urlRouterProvider
.when(
'/:resource?collection&type&id',
[
'$match', '$stateParams',
function routeValidator( $match , $stateParams )
{
var path = '';
angular.forEach($match, function joinner( val , key )
{
if ( angular.isDefined(val) ) path += '/' + val;
});
return path;
}
]
)
.when( '' , '/about' )
.when( '/' , '/about' )
.otherwise( '/404' );
然后是几种状态:$stateProvider
.state('about',
{
"url": "/about",
"templateUrl": "about.tmpl"
}
)
//…
我尝试打index.html#/
或index.html#/about
,但没有任何状态被调用(随后没有任何 Controller 被调用)。但是遵守我的路线(例如,“”被重定向到“/ about”)。没有控制台错误,也不会按预期返回值(例如index.html#/about
,$ match和path = /about
)。编辑
看来Require是问题的一部分:
最佳答案
原来我是个白痴:当我从ngRouter切换到ui.router时,我忘记了将ng-view
切换为ui-view
。工作插件:http://plnkr.co/edit/ZckIBlayuB10hooJ0sY5