我有一个父状态 (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',
});
父 View 包含嵌套的ui-view
即:在views/parent.html
中:
<h1>Child:</h1>
<div ui-view></div>
当我更改为子状态时,父状态的 URL 将前缀添加到 templateUrl
中。
即:templateUrl
正在解析为 /parent/views/child.html
此操作失败,因为 /parent/views/child.html
不存在。 (该文件存储在/views/child.html
下)
如何配置 ui-router
不将父状态的 url 前缀到 templateUrl
上?
最佳答案
这不是用户界面路由器问题。您应该在模板 url 前面添加斜杠,以便它相对于基本 url 而不是当前 url。
所以:
templateUrl : '/views/child.html'
关于javascript - ui-router 使用父级的 url 作为嵌套 View 模板的前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21821897/