我正在将ui-router 0.3.2升级到1.0.0,并面临着一个问题,尽管状态发生了变化,但没有呈现任何视图。
我遵循了这个migration document
并且我使用了polyfill Transition Hook重新启用$stateChangeStart
角度事件。
某些代码
说明路由:
$stateProvider.state('root', {
url: '/',
data: {
displayName: 'AppName'
},
views: {
'content@': {
templateUrl: 'content/content.html'
},
'accountStatus@': {
templateUrl: 'pm/accountstatus/account-status.html',
controller: 'AccountStatusController',
controllerAs: '$ctrl'
}
},
resolve: { activeUser },
onEnter: ['activeUser', '$state', 'MenuService', (user: User, $state: any, menuService: MenuService) => {
if (user.hasContracts())
return $state.go('contracts')
else
menuService.setCurrentMenu(menuService.getUserWelcomeMenu());
}]
}).state('pm', {
url: '/pm',
abstract: true,
resolve: { activeUser },
views: {
'content@': {
templateUrl: 'content/content.html'
}
}
}).state('contracts', {
url: '/contracts',
views: {
'content@': {
templateUrl: 'content/content.html'
},
'main@': {
templateUrl: 'contracts/contracts.html',
controller: 'ContractsController',
controllerAs: '$ctrl'
},
'accountStatus@': {
templateUrl: 'pm/accountstatus/account-status.html',
controller: 'AccountStatusController',
controllerAs: '$ctrl'
}
},
data: {
displayName: '{{\'user.menu.contracts\' | translate}}'
},
resolve: { activeUser }
})
Index.html
<!DOCTYPE html>
<!--BUILD_VERSION-->
<html ng-app="app" class="{{stateId}}">
<div ui-view="content"></div>
</body>
</html>
content.html
<div ng-controller="ContentController as $ctrl">
<div ui-view="accountStatus@"></div>
<div ui-view="contractStatus@"></div>
<div ui-view="main@"></div>
</div>