javascript - ui-router 使用父级的 url 作为嵌套 View 模板的前缀

标签 javascript html angularjs angular-ui-router

我有一个父状态 (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/

相关文章:

javascript - 数组长度在清空后不会增加,并且无法在 HTMLCollection 上添加鼠标事件

javascript - 使用 jQuery 创建并排幻灯片的问题

javascript - 取出图片标签 alt :missing. "image tag without an alt id is prefered and not showing missing"

android - Cordova android 模拟器 - 如何使用本地主机?

javascript - 在 ExpressJS Generator 中,Views 文件夹有什么用?

javascript - 点击函数中的 jQuery 语法错误

javascript - 查找缺失的yield语句

javascript - LABjs 有条件地加载脚本

javascript - 如何使用鼠标在内容上滚动可滚动的 div?

javascript - 为什么 Or 不能在 angularJs ng-pattern 中工作?