当使用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)
此问题不会发生.我假设父状态正在重新初始化,但为什么呢?
.go调用子状态时父状态会重新初始化?