相关疑难解决方法(0)

Angular JS ui-router如何从父级重定向到子状态?

当使用onEnter重定向到某个状态时,如果新状态是当前状态的子状态,则会发生无限循环.

例:

$stateProvider
  .state 'inventory',
    url: '/inventory'
    templateUrl: 'views/inventory.html'
    controller: 'InventoryCtrl'
    onEnter: () ->
      $state.go 'inventory.low'
  .state 'inventory.low',
    url: '/low'
    templateUrl: 'views/inventory-table.html'
    controller: 'LowInventoryCtrl'
Run Code Online (Sandbox Code Playgroud)

什么时候:

$state.go 'inventory.low'
Run Code Online (Sandbox Code Playgroud)

被调用,状态inventory被重新初始化,导致它被再次调用=无限循环.

但是,如果重定向状态是:

$state.go 'otherStateThatIsNotAChild'
Run Code Online (Sandbox Code Playgroud)

此问题不会发生.我假设父状态正在重新初始化,但为什么呢?

  1. 为什么在.go调用子状态时父状态会重新初始化?
  2. 然后,你会怎样处理重定向到儿童状态?

javascript angularjs angular-ui-router

14
推荐指数
2
解决办法
3万
查看次数

标签 统计

angular-ui-router ×1

angularjs ×1

javascript ×1