gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 16:45:22 25 4
gpt4 key购买 nike

我面临着非常奇怪的情况,我在这里使用了 Angular 状态,这是我的状态代码

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>

提前致谢

最佳答案

你能试试这个吗

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);

});

关于javascript - Angularjs 路由状态正在加载无限时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39270270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com