我刚刚在我的AngularJS
应用程序中添加了嵌套状态,但是如果父状态被命中,我还想添加重新路由,所以我将此代码添加到我的UI-router
angular.module('app')
.config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.when('/PDGODSTD', '/PDGODSTD/weekinfo');
$stateProvider.state('PDGODSTD', {
//abstract: true, // uncommenting this resolves in an error telling me that I can't navigate to an abstract state
url: "/PDGODSTD",
templateUrl: '../Modules/PDGODSTD/web/index.html'
})
.state('PDGODSTD.weekinfo', {
url: "/weekinfo",
templateUrl: '../Modules/PDGODSTD/web/weekinfo/weekinfo.html',
controller: 'PDGODSTDweekinfoController',
resolve: {
}
})
});
index.html文件只包含这段代码<ui-view><ui-view />
路由器在父状态和嵌套状态之间保持重新路由和第四,或者在Chrome
的调试器中出现。
答案 0 :(得分:1)
这个简单的plunker似乎有效:http://plnkr.co/edit/8O7YZY9vBsCW0Wbj6ygU?p=preview
检查您的templateUrl是否正确获取(检查网络选项卡)。
在ui-router 1.0.0-rc.1中,重定向的首选机制是使用redirectTo:
。
redirectTo
的文档位于:https://ui-router.github.io/ng1/docs/latest/interfaces/ng1.ng1statedeclaration.html#redirectto
$stateProvider.state('PDGODSTD', {
redirectTo: 'PDGODSTD.weekinfo',
url: "/PDGODSTD",
templateUrl: '../Modules/PDGODSTD/web/index.html'
})
.state('PDGODSTD.weekinfo', {
url: "/weekinfo",
templateUrl: '../Modules/PDGODSTD/web/weekinfo/weekinfo.html',
controller: 'PDGODSTDweekinfoController',
resolve: {
}
})
答案 1 :(得分:0)
错误发生在我的index.html
文件中。结束标记错误,应该是<ui-view></ui-view>
而不是<ui-view><ui-view />
克里斯的回答是正确的,因为他告诉我错误不在逻辑中,而在其他地方