我有一个角6应用程序的基础href设置为/dashboard/。生成的文件a位于服务器上,使用--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。
我在这里做了什么错事?
发布于 2019-02-22 08:33:49
如果在index.html路径上找不到文件,则需要设置索引文件和重定向文件
location /dashboard {
alias /<path_to_built_files>/frontend/dist/frontend/;
index index.html;
try_files $uri $uri/ index.html =404;
}发布于 2019-02-22 08:34:45
您可以使用散列 https://codecraft.tv/courses/angular/routing/routing-strategies/,这有助于记住浏览器的URL。它使用URL的散列片段部分来存储客户端的状态,它更容易设置,并且不需要服务器端的任何合作。所以,只需在路由器配置中添加
useHash,如下所示-
RouterModule.forRoot(appRoutes, {useHash: true});然后,您可以重新构建应用程序&部署到生产中。您将看到一个#添加到您的URL。
https://stackoverflow.com/questions/54822912
复制相似问题