var app= angular
. Module (' app ', [
' Nganimate ',
' Ngcookies ',
' Ngresource ',
' Ngsanitize ',
' Ngtouch ',
' Ui.router ',
' Ui.bootstrap ',
' Datatablesdirectives ',
' Ngtable ',
' Ncy-angular-breadcrumb ',
' Ngfileupload ',
' Messagecentermodule ',
' Angular-loading-bar ',
' Toggle-switch '
])
. Run (
[' $rootScope ', ' $state ', ' $stateParams ', ' appsession ',
function ($rootScope, $state, $stateParams, appsession) {
$rootScope. $state = $state;
$rootScope. $stateParams = $stateParams;
$rootScope. $on (' $stateChangeStart ', function (event, tostate, Toparams, FromState, Fromparams) {
$state. previous = FromState;
$state. previousparams = Fromparams;
if (ToState.data.requiredLogin &&!) Appsession.getlogin () &&!toparams.tokenandname) {
$state. Go (' login ', {}, {
Reload:true
});
Event.preventdefault ();
}
});
}
]
). config ([' Cfploadingbarprovider ', function (Cfploadingbarprovider) {
Cfploadingbarprovider.includespinner = true;
}])
. config (
[' $stateProvider ', ' $urlRouterProvider ', ' $breadcrumbProvider ', ' $httpProvider ',
function ($stateProvider, $urlRouterProvider, $breadcrumbProvider, $httpProvider) {
$httpProvider. Interceptors.push (' Tokeninterceptor ');
$urlRouterProvider. Otherwise ('/');
$stateProvider
. State (' login ', {
URL: '/',
Templateurl: ' views/login/login.html ',
Controller: ' Loginctrl ',
Data: {
Requiredlogin:false
}
})
. State (' main ', {
URL: '/main ',
Abstract:true,
Templateurl: ' main.html ',
Data: {
Requiredlogin:true
},
Ncybreadcrumb: {
Label: ' Home '
}
})
. State (' Main.mywork ', {
URL: '/mywork ',
Templateurl: ' views/mywork/myworklist.html ',
Controller: ' Myworkcontroller ',
Ncybreadcrumb: {
Label: ' My Workbench ',
Parent: ' Main '
},
Data: {
Requiredlogin:true
}
}).......
Status Change Events
$scope . $on ( ' $ Statechangestart ' function ) { //If you need to block the completion of the event
event. preventdefault();
});
< Span class= "token punctuation" > parameters:
event:该事件的基本信息
toState:我们可以得到当前路由的信息,比如路由名称,url,视图的控制器,模板路径等等
toParams:We can get the parameters of the current route
fromState:We can get information on the last route, such as the route name, URL, view controller, template path, etc.
fromParams:We can get the parameters of the previous route
The events that can be triggered include:
Statechangestart
Triggered when the state change is started
$stateChangeSuccess
Triggered when the status change is successful
$stateChangeError
When a state change encounters an error, the error is usually that the target cannot be loaded, the pre-loaded data cannot be loaded, and so on.
According to the above: the user is not logged in the case, jump to the routing main.mywork, should be redirected to the login page. But found jumps.
After several twists and turns, found himself too careless. Not introduced
The ' ui.router.state.events ' module, index.html page also did not introduce a response to the stateevents.js.
Once Angularjs routing $stateChangeStart not working (details determine success or failure)