摘要: $stateChangeStart- 當模板開始解析之前觸發 $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams){ ... })
app.run(['$rootScope', '$location' ,'$cookieStore', '$state', 'CacheManager', function($rootScope, $location, $cookieStore, $state,CacheManager){
//監聽路由事件
$rootScope.$on('$stateChangeStart',
function(event, toState, toParams, fromState, fromParams){
if(toState.name=="tabs.post"&&fromState.name=="tabs.orderList"){
//$location.path();//獲取路由地址
$location.path('/tabs/home');//設置路由地址
}
})
}]);
ps:
使用event.preventDefault()可以阻止模板解析的發生
$rootScope.$on('$stateChangeStart',
function(event, toState, toParams, fromState, fromParams){
event.preventDefault();
})
$stateChangeSuccess- 當模板解析完成后觸發 $stateChangeError- 當模板解析過程中發生錯誤時觸發 $viewContentLoading- 當視圖開始加載,DOM渲染完成之前觸發,該事件將在$scope鏈上廣播此事件 $viewContentLoaded- 當視圖加載完成,DOM渲染完成之后觸發,視圖所在的$scope發出該事件。
參考原文:https://my.oschina.net/jack088/blog/479466
