UI 路由器 $state.go 未重定向
UI Router $state.go is not redirecting?
这是一个
常见问题,我看到了很多,但似乎没有任何效果。这就是我正在做的事情。我想在我的状态中有一些动态动画,所以基本上登录会做一些很酷的动画并进入实际界面。现在,我开始像这样嵌套视图:
$stateProvider
.state('login', {
url: '/login',
title: "Login",
views: {
"master": {
controller: "LoginController",
templateUrl: "/components/login/login.html",
authentication: false
}
}
})
.state("logout", {
url: "/logout",
title: "Logout",
authentication: false
})
.state('foo', {
url: '/',
controller: "HomeController",
views: {
"master": {
templateUrl: '/components/ui-views/masterView.html'
},
"sidebar@foo": {
templateUrl: '/components/sidebar/_sidebar.html'
},
"header@foo": {
templateUrl: '/components/header/_header.html'
}
}
})
.state('foo.inventory', {
url: '/inventory',
title: "Inventory",
views: {
"content@foo": {
controller: "InventoryController",
templateUrl: "/components/inventory/inventory.html"
}
}
});
因此,在运行此功能时,我需要重定向到注销,但它卡住了。它根本不会从此注销状态移动。以下是我的处理方式:
function run($http, $rootScope, $cookieStore, $state, $templateCache, $timeout, AuthService, modalService, const) {
var timeout;
FastClick.attach(document.body);
$rootScope.globals = $cookieStore.get('globals') || {};
if ($state.current.name !== 'login' && !$rootScope.globals.guid) {
$state.go('login');
} else if ($state.current.name == 'login' && $rootScope.globals.guid) {
$state.go('foo');
}
$rootScope.$on('$stateChangeStart', function (event, next, current, fromState, fromParams) {
var authorizedRoles = next.level != undefined ? next.level : 1,
needAuth = next.authentication != undefined ? next.authentication : true;
if (needAuth) {
if (!AuthService.isAuthorized(authorizedRoles, true)) {
event.preventDefault();
if (AuthService.isAuthenticated()) {
$rootScope.$broadcast(const.auth.notAuthorized);
$state.go('foo', {});
} else {
$rootScope.$broadcast(const.auth.notAuthenticated);
}
}
}
if (next.name == 'logout') AuthService.logout($rootScope.globals);
});
}
那么为什么这行不通呢?看起来这工作正常。但$state.go('login')
返回一个错误的值。
如果有人能引导我朝着正确的方向前进,或者告诉我到底出了什么问题。
问题是 $state.go 正在运行,关于这个主题的文档似乎并不多。 $state.go 尚未初始化,不会运行。
我遇到了同样的问题。在调试了属性ui-sref
如何用于超链接后,我发现$state.go
在核心 angular-ui 库中环绕着$timeout。
var transition = $timeout(function() {
debugger;
$state.go("app.authentication");
});
也许你可以尝试同样的方法。(尽管核心库中的 ui-sref 事件处理程序明确提到这是一个黑客。
只需要升级ui-router版本就可以了,见连接地址:https://github.com/mattlewis92/angular-bluebird-promises/issues/11
如果你升级到ui-router 0.3.2,它实际上已经在那里修复了:angular-ui/ui-router@66ab048
我在应用程序中遇到了这个问题,您正在尝试在与状态无关的内部ui-view
上调用$state.go
,这就是您面临的问题,因此请尝试以下操作:
app.run(['$state', '$rootScope', '$timeout',
function ($state, $rootScope, $timeout) {
$timeout(function() {
$state.go('login');
});
}]);
相关文章:
- 通过javascript重定向html传递php变量
- JavaScript下拉菜单-点击按钮并根据所选值重定向到url
- 使用angular重定向到html页面
- 如何在chrome扩展中重定向到html页面
- 无法从jquery Mobile导航栏重定向到另一个页面
- ng视图外的链接重定向到ng视图内的页面
- 在phonegap应用程序内部重定向不起作用
- CORS-重定向到第二个GET正在接收的页面
- AJAX不会在文件上传后重定向到网页-POST方法
- 重定向时角度刷新浏览器
- 通过链接重定向不;我不在jstree中工作
- 根据select选项元素将表单重定向到不同的URL
- 通过JQuery重定向到另一个页面
- 重定向到“父窗口”
- 重定向iFrame中的父URL
- PHP-如何重定向到同一页面并更改DOM's
- chrome.tabs.update() 重定向到 'chrome-extension://invalid/'
- Meteor JS Router.go重定向到同一页面
- UI 路由器 $state.go 未重定向
- 如何添加属性以 go.js 节点和重定向