我有一个父状态(parent
)和一个子状态(parent.child
)
$stateProvider
.state('parent', {
url: '/parent',
templateUrl: 'views/parent.html',
controller: 'parentController',
})
.state('parent.child', {
url: '/:id',
templateUrl: 'views/child.html',
controller: 'childController',
});
父视图包含嵌套的ui-view
ie:views/parent.html
:
<h1>Child:</h1>
<div ui-view></div>
当我更改为子状态时,父状态的网址<{>>前缀到templateUrl
。
即:templateUrl
被解析为/parent/views/child.html
此操作失败,因为/parent/views/child.html
不存在。 (该文件存储在/views/child.html
)
如何配置ui-router
不要将父状态的网址添加到templateUrl
前面?
答案 0 :(得分:4)
这不是ui-router问题。您应该使用斜杠添加模板URL,以使其相对于base-url而不是当前url。
所以:
templateUrl : '/views/child.html'