ng-token-auth ui 路由器解析器会导致屏幕空白

ng-token-auth ui-router resolver causes blank screen

本文关键字:屏幕 空白 ui 路由器 ng-token-auth      更新时间:2023-09-26

我正在遵循ng-token-auth的文档,试图为身份验证添加一个解析器,该解析器调用validateUser。 当我从文档中添加此代码块时,我呈现了一个空白屏幕。 我在rails服务器控制台上没有收到任何错误,在Chrome的javascript控制台上也没有收到任何错误。 知道为什么会这样吗?

这是我的应用程序.js文件,其中有问题的代码是"主页"状态的解析块。

sparkleApp = angular.module("sparkleApp",
            ['templates',
                         'validation.match',
                         'ui.bootstrap',
                         'ngSanitize',
                         'ui.router',
                         'LocalStorageModule',
                         'pippTimelineDirectives',
             'ng-token-auth',
                         'sparkleControllers',
             'sparkleServices']);
/* Controllers */
var sparkleControllers = angular.module('sparkleControllers', []);
/* Services */
var sparkleServices = angular.module('sparkleServices', []);
sparkleApp.config(['$stateProvider', '$urlRouterProvider',
                   function($stateProvider, $urlRouterProvider) {
                       $urlRouterProvider.otherwise('/');

                       // HOME STATES AND NESTED VIEWS ========================================
                       $stateProvider.state('home', {
                         url: '/',
                         views: {
                           // the main template will be placed here (relatively named)
                           '': {
                             templateUrl: 'tplHomeView.html',
                             controller: 'HomeCtrl'
                           },
                           'homeJumbotron@home': {
                             templateUrl: '_tplJumbotron.html'
                           },
                           'sparkleForm@home': {
                             templateUrl: '_tplMessageForm.html'
                           },
                           'sparkleFeatured@home': {
                             templateUrl: '_tplSparkleQuotes.html'
                           }
                         },
             resolve: {
               auth: function($auth) {
                 return $auth.validateUser();
               }
             }
                       })
                   }])
  .config(function($authProvider) {
    $authProvider.configure({
      apiUrl: '/api/v1'
    });
  });

我没有捕获$stateChangeError代码并正确处理它。 它抛出了一个未经授权的,我重定向到登录页面。

文档有所帮助,另一个堆栈溢出问题也有帮助。

https://github.com/angular-ui/ui-router/wiki#state-change-events

$state 拒绝承诺后的过渡 角度 ui 路由器