这是一个带有firebasegoogle身份验证的ionic应用程序。我想知道做这件事的正确方法,因为我的登录逻辑正常,但路由导致应用程序崩溃。不幸的是,控制台上没有错误,应用程序只是空白。
angular.module('app.routes', ['app.controllers','firebase']) .config(function($stateProvider, $urlRouterProvider) { $stateProvider .state('tabsController.allTasks', { url: '/alltasks', views: { 'tab1': { templateUrl: 'templates/allTasks.html', controller: 'allTasksCtrl', resolve : { } } } }) .state('tabsController', { url: '/page1', templateUrl: 'templates/tabsController.html', abstract:true }) .state('signup', { url: '/signup', templateUrl: 'templates/signup.html', controller: 'signupCtrl' }) .state('onboarding', { url: '/onboarding', templateUrl: 'templates/onboarding.html', controller: 'onBoardingCtrl' }) .state('logOut', { url: '/logout', templateUrl: 'templates/logOut.html', controller: 'logOutCtrl' }) .state('taskdetail', { url: '/taskdetail', templateUrl: 'templates/taskdetail.html', controller: 'allTasksCtrl' }) firebase.auth().onAuthStateChanged(function(user) { if (user) { $urlRouterProvider.otherwise('tabsController.allTasks') } else { $urlRouterProvider.otherwise('login') } });
删除.config中的firebase代码块,并将其插入.run块。
.run(function($state) { var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com"); var authData = ref.getAuth(); if (authData) { $state.go('tabsController.allTasks'); } else { $state.go('login'); } })