2015-05-19 64 views
2

我到处寻找,但没有任何潜在的解决方案已经工作。

登录页面应该在成功登录或注册后路由到标签页面。由于某种原因,它每次都会回到根目录或otherwise状态。有没有人有什么建议?谢谢!

国:

.config(function($stateProvider, $urlRouterProvider) { 

$stateProvider 
.state('intro', { 
url: '/intro', 
templateUrl: 'templates/intro.html', 
controller: 'IntroCtrl' 
}) 
.state('signin', { 
    url: '/sign-in', 
    templateUrl: 'templates/sign-in.html', 
    controller: 'SignInCtrl' 
}) 
.state('forgotpassword', { 
    url: '/forgot-password', 
    templateUrl: 'templates/forgot-password.html' 
}) 
.state('tabs', { 
    url: '/tab', 
    abstract: true, 
    templateUrl: 'templates/tabs.html' 
}) 
.state('tabs.home', { 
    url: '/home', 
    views: { 
    'home-tab': { 
     templateUrl: 'templates/home.html', 
     controller: 'HomeTabCtrl' 
    } 
    } 
}); 


$urlRouterProvider.otherwise('/intro'); 

}) 

控制器应该在登录路由的标签页:

.controller('SignInCtrl', function($scope, $state, $firebaseAuth, $location) { 

$scope.login = function(username, password) { 
    var fbAuth = $firebaseAuth(fb); 
    fbAuth.$authWithPassword({ 
     email: username, 
     password: password 
    }).then(function(authData) { 
     $location.path('/tab') 
    }).catch(function(error) { 
     console.error("ERROR: " + error); 
    }); 
} 

$scope.register = function(username, password) { 
    var fbAuth = $firebaseAuth(fb); 
    fbAuth.$createUser({email: username, password: password}).then(function() { 
     return fbAuth.$authWithPassword({ 
      email: username, 
      password: password 
     }); 
    }).then(function(authData) { 
     $location.path("/tab"); 
    }).catch(function(error) { 
     console.error("ERROR " + error); 
    }); 
} 
}) 
+1

您是否尝试过使用'$ state.go( '标签' )而不是'$ location'服务? –

回答

2

由于您使用的UI的路由器和基于状态的路由,只需拨打$state.go()快速各州之间的导航。请注意 - 您可能需要从tabs状态中删除abstract: true或转换为tabs.home。例如...

.then(function(authData) { 
    // $location.path('/tab'); 
    $state.go('tabs') 
}) 

更多信息,请参见documentation - $state.go(to [, toParams] [, options])

便捷方法用于转变到新的状态