多嵌套的ui视图

时间:2014-01-30 18:04:56

标签: angularjs angular-ui-router

这是我的配置:

$stateProvider.
  state('frontPage', {
    url: '/',
    templateUrl: 'index.html',
    controller: 'MainCtrl',
    onEnter: function() {
      console.log('frontPage');
    }
  }).
  state('frontPage.interestGame', {
    url: 'interest',
    templateUrl: 'interest-game/index.html',
    controller: 'GameCtrl',
    onEnter: function() {
      console.log('frontPage.interestGame');
    }
  }).
  state('frontPage.interestGame.game', {
    url: ':platform',
    templateUrl: 'interest-game/game.html',
    controller: 'GameCtrl',
    onEnter: function() {
      console.log('frontPage.interestGame.game');
    }
  });

我可以转到//interest,模板,控制器和onEnter函数都按预期运行。但是,当我转到/interest/anything时,它无法加载我的模板。它只是一个空的页面,没有console.log错误......我看到我的所有脚本都按预期加载了所以我知道这不是服务器问题......也许我误解了嵌套状态如何工作......?

2 个答案:

答案 0 :(得分:1)

我相信每个url州条目都必须以前导/开头。尝试将:platform更改为/:platform

答案 1 :(得分:0)

你确实需要领先/之前:平台,否则它将被解释为/interest:anything(中间没有斜线)。

此外,interest-game/index.html应包含<div ui-view></div>