我做了以下事情:
AngularJS 应用程序
在 app.js 中:
$locationProvider.html5Mode(true);
在 index.html 中:
<base href="/">
nginx配置
location / {
try_files $uri /index.html;
}
部署后,静态页面一切正常(# 井号被移除)。我可以直接进入http://fakeurl/about
或http://fakeurl/download
页面;如果我刷新浏览器,页面仍然会加载。
但是,当我直接进入动态页面时:
http://fakeurl/cars/:car_id
然后nginx会服务404。
如果我使用# 路径,那么它会重定向到没有# 符号的路径并显示页面;但是当我再次刷新页面时,它显示 404。(这只发生在动态路由上)
http://fakeurl/#/cars/:car_id
http://fakeurl/#/shops/:shop_id
我需要在 nginx 块中编写哪些重写规则来为我的动态路由提供服务?谢谢!