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

时间:2014-08-08 20:35:18

标签: javascript angularjs angular-ui-router

我试图在UI-Router中设置一个简单的嵌套视图,我之前已经这样做了,但由于某种原因,这次嵌套路由不希望被激活。

我的主要home.html正常显示并允许内容,但任何嵌套视图都不会显示。我已经检查过我的旧代码,但无法找到差异。

在我的HTML中

home.html通过ui-view

中的index.html呈现
# 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到地址栏我

Error: Could not resolve 'hello' from state 'home'

2 个答案:

答案 0 :(得分:0)

这实际上是jade的已知问题

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

答案 1 :(得分:-1)

在你的第二个.state中只使用hello,而不是home.hello,它应该有所帮助。

这里是plunker,我添加了两个链接Ahoy和Hello:

plnkr.co/edit/nautvr?p=preview