我有一个 angular 6 应用程序,base href 设置为/dashboard/
. 构建文件位于服务器上,使用--prod
标志生成。
nginx conf 看起来像:
location /dashboard {
alias /<path_to_built_files>/frontend/dist/frontend/;
}
当我第一次访问我的网站时example.com/dashboard
,应用程序完美加载,并且角度重定向到默认路由/create
。因此浏览器将我的路线显示为example.com/dashboard/create
.
这正是我希望它表现的方式。但是,如果我从这里重新加载页面,浏览器会尝试查找example.com/dashboard/create
,返回 404 Not Found。
我在这里的配置中做错了什么?
如果在以下路径上找不到文件,则需要设置索引文件和重定向index.html
:
location /dashboard {
alias /<path_to_built_files>/frontend/dist/frontend/;
index index.html;
try_files $uri $uri/ index.html =404;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句