Javascript 在Angular UI路由器的解析功能中拒绝承诺后,限制URL不更改
我有路线Javascript 在Angular UI路由器的解析功能中拒绝承诺后,限制URL不更改,javascript,angularjs,angular-ui-router,Javascript,Angularjs,Angular Ui Router,我有路线 .state('staff.dashboard', { url: '/dashboard', templateUrl: 'demo2.html', }) .state('staff.users.institutions', { url: '/institutions', templateUrl: 'demo.html', resolve: {
.state('staff.dashboard', {
url: '/dashboard',
templateUrl: 'demo2.html',
})
.state('staff.users.institutions', {
url: '/institutions',
templateUrl: 'demo.html',
resolve: {
security: [
'$q', 'UserFactory', 'AuthenticationService',
function ($q, UserFactory, AuthenticationService) {
UserFactory.setData(AuthenticationService.getUserData());
if (!UserFactory.hasInstitutionsUsersAccess()) {
return $q.reject(App.errors[401]);
}
}
]
}
})
我犯了一个错误
$rootScope.$on('$stateChangeError', function (e, toState, toParams, fromState, fromParams, error) {
if (error === App.errors[401]) {
$state.go('staff.dashboard');
}
});
因此,场景是:
- 当我在登录到应用程序之前更改URL/institutions时,由于处于institutions状态的安全性,它会将URL更改为?URL=%2Fdashboard
- 我想要的是将URL保持为?URL=%2F在中拒绝$q之后
任何帮助都是值得的。您可以使用toState和/或fromState参数:
$rootScope.$on('$stateChangeError', function (e, toState, toParams, fromState, fromParams, error) {
if (error === App.errors[401]) {
$state.go('staff.dashboard', {"url" : fromState.url});
}
});
然后,您可以在仪表板中访问url参数:
app.controller('dashboardController', function($scope, $stateParams) {
var fromUrl = $stateParams.url;
});