我使用了带有UI路由器0.2.15的angular v1.4.7,我使用了$ state.go和 ui-sref以防从html转到另一个状态。我无能为力 回去。我检查了浏览器的后退/前进按钮,但我没有看到任何历史记录被推入。所以,一旦我点击后退按钮,它就会将我发送到空白标签。
'use strict';
/**
* Config for the router
*/
angular.module('app').run(
['$rootScope', '$state', '$stateParams',
function($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
}
]).config(
['$stateProvider', '$urlRouterProvider', 'JQ_CONFIG', 'MODULE_CONFIG',
function($stateProvider, $urlRouterProvider, JQ_CONFIG, MODULE_CONFIG) {
var layout = "tpl/app.html";
$stateProvider.state('app', {
abstract: true,
url: '/app',
templateUrl: layout,
data: {
permissions: {
exept: ['anonymous'],
redirectTo: 'access.signin'
}
},
resolve: load(['toastr', 'js/controllers/modal.js'])
}).state('app.dashboard', {
url: '/dashboard/:tagName',
templateUrl: 'tpl/app_dashboard_v1.html',
controller: 'DashboardController',
data: {
permissions: {
only: ['USER']
}
},
resolve: load(['toastr', 'js/controllers/dashboard.js'])
}).state('app.chat', {
url: '/chat',
templateUrl: 'tpl/chat.html',
controller: 'chatCtrl',
data: {
permissions: {
only: ['USER']
}
},
resolve: load(['toastr', 'js/controllers/chatCtrl.js'])
}).state('app.accounts', {
url: '/accounts/:accountId/:tagName',
templateUrl: 'tpl/group_dash.html',
controller: 'GroupDashController',
data: {
permissions: {
only: ['USER']
}
},
resolve: load(['toastr', 'js/controllers/group_dashboard.js'])
}).state('app.profile', {
url: '/profile/:accountId',
templateUrl: 'tpl/user_profile.html',
data: {
title: 'Profile'
},
controller: 'UserProfileController',
controllerAs: 'vm',
resolve: load(['toastr', 'js/controllers/profile.js'])
}).state('app.feedback', {
url: '/feedback',
templateUrl: 'tpl/feedback.html',
controller: 'feedbackController',
controllerAs: 'vm',
data: {
permissions: {
only: ['USER']
}
},
resolve: load(['toastr', 'js/controllers/feedback.js'])
}).state('access', {
url: '/access',
template: '<div ui-view class="fade-in-right-big smooth"></div>'
}).state('access.signin', {
url: '/signin',
templateUrl: 'tpl/page_signin.html',
resolve: load(['js/controllers/signin.js'])
}).state('access.signout', {
url: '/signout',
templateUrl: 'tpl/page_signout.html',
controller: "SignoutController",
controllerAs: "vm",
data: {
permissions: {
only: ['USER']
}
},
resolve: load(['js/controllers/signout.js'])
}).state('access.signup', {
url: '/signup',
controller: "SignUpController",
controllerAs: "vm",
templateUrl: 'tpl/page_signup.html',
resolve: load(['toastr', 'js/controllers/signup.js'])
}).state('access.forgotpwd', {
url: '/forgotpwd',
controller: "ForgotPassController",
templateUrl: 'tpl/page_forgotpwd.html',
resolve: load(['js/controllers/forgotpwd.js'])
}).state('access.404', {
url: '/404',
templateUrl: 'tpl/page_404.html'
});
$urlRouterProvider.otherwise(function($injector) {
var $state = $injector.get("$state");
$state.go('app.dashboard');
});
function load(srcs, callback) {
return {
deps: ['$ocLazyLoad', '$q',
function($ocLazyLoad, $q) {
var deferred = $q.defer();
var promise = false;
srcs = angular.isArray(srcs) ? srcs : srcs.split(/\s+/);
if (!promise) {
promise = deferred.promise;
}
angular.forEach(srcs, function(src) {
promise = promise.then(function() {
if (JQ_CONFIG[src]) {
return $ocLazyLoad.load(JQ_CONFIG[src]);
}
angular.forEach(MODULE_CONFIG, function(module) {
if (module.name == src) {
name = module.name;
} else {
name = src;
}
});
return $ocLazyLoad.load(name);
});
});
deferred.resolve();
return callback ? promise.then(function() {
return callback();
}) : promise;
}
]
}
}
}
]);