刷新页面Angular 7后无法获取/ route

时间:2019-12-21 11:03:42

标签: angular server routing live

我在Angular 7中有一些组件,并且我不使用'useHash:true'进行路由。

我在实时服务器上部署了Angular应用程序,如果我使用路由导航到某个组件(例如/ panel),则它工作正常,但是如果我重新加载该页面,则会出现错误“无法获取/ panel”

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

在您的应用中运行此CLI命令

ng build --prod="true" --base-href="<Your-Base-Path/<your-project-folder-name>"

,这将在index.html中使用您定义的路径设置基本路径,因此,每次刷新页面时,它都会位于根文件夹的底部。

现在您的index.html文件具有此base-path

<base href="<Your-Base-Path/<your-project-folder-name>">

答案 1 :(得分:0)

您应该将服务器配置为回退到index.html。 查看angular docs here如何做到这一点。 例如,在Appcache服务器上,我正在使用此.htaccess文件:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^(.*) /index.html [NC,L]
相关问题