javascript - ui-router 中的嵌套路由无法解析

标签 javascript angularjs angular-ui-router

我正在尝试在 UI-Router 内部设置一个简单的嵌套 View ,我之前已经这样做过,但由于某种原因,这次嵌套路由不想被激活。

我的主 home.html 正常显示并允许内容,但不会出现任何嵌套 View 。我检查了我的旧代码,没有发现任何差异。

在我的 HTML 中

home.html 通过 index.html 中的 ui-view 呈现

# Home.html
<p>Hello World<a ui-sref="hello">
    <button>go hello</button></a>
  <div ui-view></div>
</p>


# Hello.html
<p>Hello HTML</p>

在我的 app.js 中,我有:

angular.module('concierge.customer',
    ['ngCookies',
     'ui.router',
     'restangular'
    ])

    .config(function($stateProvider, $urlRouterProvider) {
        $urlRouterProvider.otherwise('/')

            $stateProvider
                .state('home', {
                url: '/',
                controller: function() {
                  console.log('Home Base')
                },
                        templateUrl: 'modules/home/home.html'
                })
            .state('home.hello', {
                url: '/hello',
                controller: function() {
                  console.log('Home Hello')
                },
                templateUrl: 'modules/home/hello.html'
            })
    })

    .run(['$rootScope', function($rootScope) {
        $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
            console.log("You are going from ", fromState);
            console.log('To: ', toState);
        })
    }])

如果我在地址栏手动输入/hello,我会得到

错误:无法从状态“home”解析“hello”

最佳答案

这实际上是 Jade 的一个已知问题

https://github.com/angular-ui/ui-router/issues/247

关于javascript - ui-router 中的嵌套路由无法解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25211837/

相关文章:

javascript - 为什么图标不显示在使用 Angular js 的列表中?

javascript - 如何在buttonClicked上调用$ionicActionSheet之外的函数?

javascript - 如何将多个文件选择放入数组中然后输出到 HTML

javascript - JQuery 弹跳是不是跳错了地方?

javascript - var notification = 新通知

angularjs - 如何在ejs中发送对象作为函数参数

javascript - 事件子状态在不应使用 ng-class 和 ui-router 时保持事件状态

javascript - 使用 gulp 进行丑化时,Angular-ui-router 会中断

java - 从服务器端 API 重定向时,Safari Angular URL 参数被忽略

javascript - 鼠标悬停或单击链接/按钮时的菜单可扩展 CSS 脚本