Angularjs路由状态正在加载无限时间

时间:2016-09-01 11:25:35

标签: javascript angularjs

我面临着非常疲惫的局面,我在这里使用过角度状态是我的状态代码

APP.config(function($stateProvider, $urlRouterProvider,$locationProvider) {
console.log('in config');
$locationProvider.html5Mode({
  enabled: true,
  requireBase: false
});
// Default state

$stateProvider

// Home state defining here -----
.state('/', {
    url: '/',
    templateUrl: 'app/components/home/home.view.html',
    controller: 'homeController'
})

// Search result state defining here
.state('search', {
    url: '/search',
    templateUrl: 'app/components/search-result/search.view.html',
    controller: 'searchController',
})

// product detail state defining here
.state('product', {
    url: '/product/:id',
    templateUrl: 'app/components/product-detail/product-detail.view.html',
    controller: 'productDetailController',
});

     $urlRouterProvider.otherwise('/');

    // use the HTML5 History API

    $locationProvider.html5Mode(true);

});

当我刷新页面时,所有状态都没有工作,那么我在这里做了一些服务器端ngnix配置是ngnix配置。

server {
listen 80;
listen 443 ssl http2;
server_name shop.dev;
root "/home/vagrant/Code/shop";

index index.html;

charset utf-8;

location / {
    try_files $uri $uri/ /index.html;
}


location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt  { access_log off; log_not_found off; }

access_log off;
error_log  /var/log/nginx/shop.dev-error.log error;

sendfile off;

client_max_body_size 100m;

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    fastcgi_intercept_errors off;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
}

location ~ /\.ht {
    deny all;
}


ssl_certificate     /etc/nginx/ssl/shop.dev.crt;
ssl_certificate_key /etc/nginx/ssl/shop.dev.key;
}

现在的问题是,当用户重定向到 product / productName 路由时,在刷新页面上启动无限循环并且我的productControoler调用无限时间一切都停留:(

这是html

<body ng-app="shopApp">
<!--- loading header layout -->
<div ng-include="'app/shared/layout/header/header.view.html'">  </div>
  <div class="container" id="content" ng-class="{}">
    <!--- load view here -->
    <div ui-view></div>
  </div>
  <!--- loading footer layout -->
 <div ng-include="'app/shared/layout/footer/footer.view.html'"></div>
<!-- Including Js scripts -->
<script src="http://shop.dev/build/vendor.js"></script>
<script src="http://shop.dev/build/app.js"></script>

 </body>

提前致谢

1 个答案:

答案 0 :(得分:0)

请你试试这个

APP.config(function($stateProvider, $urlRouterProvider, $locationProvider) {
  console.log('in config');
  $urlRouterProvider.otherwise('/Home');
  // Default state

  $stateProvider
  // Home state defining here -----
  .state('Home', {
    url: '/Home',
    templateUrl: 'app/components/home/home.view.html',
    controller: 'homeController'
  })

  // Search result state defining here
  .state('search', {
    url: '/search',
    templateUrl: 'app/components/search-result/search.view.html',
    controller: 'searchController'
  })

  // product detail state defining here
  .state('product', {
    url: '/product/:id',
    templateUrl: 'app/components/product-detail/product-detail.view.html',
    controller: 'productDetailController'
  });

  // use the HTML5 History API

  $locationProvider.html5Mode(true);

});