直接上代码
app.run(['$rootScope', '$window', '$location', '$log', function ($rootScope, $window, $location, $log) {
var locationChangeStartOff = $rootScope.$on('$locationChangeStart', locationChangeStart);
var locationChangeSuccessOff = $rootScope.$on('$locationChangeSuccess', locationChangeSuccess);
var routeChangeStartOff = $rootScope.$on('$routeChangeStart', routeChangeStart);
var isSecond = false;
function locationChangeStart(event, newUrl, currentUrl) {
console.log('arguments = ', arguments);
console.log('newUrl = ', newUrl);
console.log('decode -> newUrl = ', decodeURIComponent(newUrl));
console.log('currentUrl = ', currentUrl);
if (decodeURIComponent(newUrl) == currentUrl) {
console.log('currentUrl.indexof = ', currentUrl.indexOf('upload_topic_image'));
if (currentUrl.indexOf('upload_topic_image') >= 0) {
if (isSecond) {
console.log("$location.path('http://ctb.qingguo.com/weixinCt/main#/upload_topic_start')");
$location.path('http://ctb.qingguo.com/weixinCt/main#/upload_topic_start');
isSecond = false;
} else {
isSecond = true;
console.log('isSecond = ', isSecond);
}
event.preventDefault();
return;
}
}
console.log('判断结束 ');
}
function locationChangeSuccess(event, newUrl, currentUrl) {
console.log('arguments = ', arguments);
console.log('newUrl = ', newUrl);
console.log('decode -> newUrl = ', decodeURIComponent(newUrl));
console.log('currentUrl = ', currentUrl);
if (decodeURIComponent(newUrl) == currentUrl) {
console.log('currentUrl.indexof = ', currentUrl.indexOf('upload_topic_image'));
if (currentUrl.indexOf('upload_topic_image') >= 0) {
if (isSecond) {
console.log("$location.path('http://ctb.qingguo.com/weixinCt/main#/upload_topic_start')");
$location.path('http://ctb.qingguo.com/weixinCt/main#/upload_topic_start');
isSecond = false;
} else {
isSecond = true;
console.log('isSecond = ', isSecond);
}
event.preventDefault();
return;
}
}
console.log('判断结束 ');
}
function routeChangeStart(event, newUrl, currentUrl) {
console.log('routeChangeStart-----开始 ');
console.log('arguments = ', arguments);
if(newUrl != undefined && currentUrl != undefined && newUrl.$$route != undefined && currentUrl.loadedTemplateUrl !=undefined) {
console.log('newUrl = ', newUrl);
console.log('newUrl.url = ', newUrl.$$route.templateUrl);
console.log('currentUrl = ', currentUrl.loadedTemplateUrl);
if (newUrl.$$route.templateUrl == currentUrl.loadedTemplateUrl) {
console.log('currentUrl.indexof = ', currentUrl.loadedTemplateUrl.indexOf('upload_topic_image'));
if (currentUrl.loadedTemplateUrl.indexOf('upload_topic_image') >= 0) {
console.log("$location.path('http://ctb.qingguo.com/weixinCt/main#/upload_topic_start')");
$location.path('http://ctb.qingguo.com/weixinCt/main#/upload_topic_start');
isSecond = false;
event.preventDefault();
return;
}
}
}
console.log('routeChangeStart-----结束 ');
}
}]);