ui路由器在使用Gulp缩小后不起作用



我用Angular制作应用程序,并使用Gulp缩小所有文件css,javascript。但是,如果我运行gulp build来缩小,然后在dist文件夹中运行文件"index.html",则ui路由器不会加载模板。在文件 html 中,标记 a 仍然像这样:<a ui-sref='link'> LINK </a> 。是你帮我的好意!这是链接代码:

应用.jshttps://gist.github.com/quyen91/d4ca009bb0be0e42a5a9dbded76ec45a

古尔普文件.jshttps://gist.github.com/quyen91/bd04688302847a964e16586f9b468d29

错误:https://cdn.pbrd.co/images/1EjGpl8T.png

Ui 路由器和许多工厂通常会停止工作,因为当我们不缩小时,我们总是将其提供程序的正确名称注入控制器或配置或运行或其他任何东西的参数中。但是当缩小时,发生的事情是

run(function($state,$rootScope,$http){})
would become 
run(function(x,y,z){})

这会导致问题。.

因此,单独编写提供程序的名称始终是一种很好的做法。因此,该函数变为

run(['$state','$rootScope','$http',function($state,$rootScope,$http){}]);
to 
run(['$state','$rootScope','$http',function(x,y,z){}]);

但是这里的变量提供者是正确的,因此它不会导致任何错误。

在您的情况下,运行方法应该像

.run(['$rootScope', '$state', 'auth', 'jwtHelper', '$location', 'store',function($rootScope, $state, auth, jwtHelper, $location, store) {

    $rootScope.$on('$locationChangeStart', function() {
    // Get the JWT that is saved in local storage
    // and if it is there, check whether it is expired.
    // If it isn't, set the user's auth state
    var token = store.get('token');
    if (token) {
      if (!jwtHelper.isTokenExpired(token)) {
        if (!auth.isAuthenticated) {
          auth.authenticate(store.get('profile'), token);
        }
      }
    }
    else {
      // Otherwise, redirect to the home route
      $location.path('/about');
    }
  });

配置应该以

.config(['$stateProvider', '$urlRouterProvider', 'authProvider', '$httpProvider', '$locationProvider',
  'jwtInterceptorProvider',function ($stateProvider, $urlRouterProvider, authProvider, $httpProvider, $locationProvider,
  jwtInterceptorProvider) {
.....
}]);
<</div> div class="one_answers">

您的.run.config块不是缩小安全的。

试试这个.run

.run(['$rootScope', '$state', 'auth', 'jwtHelper', '$location', 'store', function($rootScope, $state, auth, jwtHelper, $location, store) {

    $rootScope.$on('$locationChangeStart', function() {
    // Get the JWT that is saved in local storage
    // and if it is there, check whether it is expired.
    // If it isn't, set the user's auth state
    var token = store.get('token');
    if (token) {
      if (!jwtHelper.isTokenExpired(token)) {
        if (!auth.isAuthenticated) {
          auth.authenticate(store.get('profile'), token);
        }
      }
    }
    else {
      // Otherwise, redirect to the home route
      $location.path('/about');
    }
  });
}]);

config做同样的事情。

最新更新