【问题标题】:ui-router prefixes nested view templates with the parent's urlui-router 为嵌套视图模板添加父级 url 前缀
【发布时间】:2014-02-17 14:54:14
【问题描述】:

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

即:在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 上?

【问题讨论】:

    标签: javascript html angularjs angular-ui-router


    【解决方案1】:

    这不是 ui-router 问题。您应该在模板 url 前面加上一个斜杠,以便它相对于 base-url 而不是当前 url。

    所以:

    templateUrl : '/views/child.html'
    

    【讨论】:

      猜你喜欢
      • 2018-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-20
      • 2014-01-26
      相关资源
      最近更新 更多