Javascript UI路由器$state.go没有重定向吗?

Javascript UI路由器$state.go没有重定向吗?,javascript,angularjs,angular-ui-router,Javascript,Angularjs,Angular Ui Router,这是一个常见的问题,我看了很多,但似乎没有任何效果。这就是我正在做的。我想有一些动态动画与我的状态,所以基本上登录会做一些很酷的动画,并进入实际的界面。现在,我开始像这样嵌套视图: $stateProvider .state('login', { url: '/login', title: "Login", views: { "master": {

这是一个常见的问题,我看了很多,但似乎没有任何效果。这就是我正在做的。我想有一些动态动画与我的状态,所以基本上登录会做一些很酷的动画,并进入实际的界面。现在,我开始像这样嵌套视图:

    $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
在核心ui库中是围绕$timeout包装的

var transition = $timeout(function() {
                debugger;
                $state.go("app.authentication");
            });

也许你也可以试试。(尽管核心库中的ui sref事件处理程序明确指出这是一种黑客行为。)

只需要升级用户界面路由器版本就可以了,见连接地址:


如果你升级到ui路由器0.3.2,它实际上已经被修复了:角度ui/ui-router@66ab048

我在我的应用程序中遇到了这个问题,您正在尝试调用
$state。在与状态无关的内部
ui视图上运行
,这就是您面临的问题,请尝试以下操作:

app.run(['$state', '$rootScope', '$timeout', 
function ($state, $rootScope, $timeout) {

 $timeout(function() { 
      $state.go('login');
    });   
}]);

只需尝试window.location.hash=“#login”;而不是$state.go('login')…它只是在URL末尾散列登录名,不能完成我需要它做的事情。缺少很多部分,例如$rootScope.globals.guid,或者$rootScope之前的if。$on调用where?。。。最好是用一些plunker重现这个问题,或者分享所有的东西。它正在进入
$state.go('login')但实际调用返回:
值:错误:由于某种原因转换被取代。不知道为什么。即使使用$location.path('/login');它不起作用。@MikeHuebner$state.go到底在哪里?你的整个代码的包装函数是什么?省去了我很多麻烦。注意,官方语言是英语,因为很难监控多语言帖子。请确保您将回复翻译成英语。