在刷新页面上,未发现错误,需要不使用 # 的解决方案

on refreshing page , not found error, need solution without using #

我有一个 angular 9 项目。我将它部署到服务器。在服务器上,当我刷新 angular 应用程序时,它显示错误:

错误:

开始

未找到

在此服务器上找不到请求的 URL。

此外,在尝试使用 ErrorDocument 处理请求时遇到了 404 Not Found 错误。

结束

我们正在使用下面的开发

服务器:阿帕奇

前端:angular

后端:nodejs

我不明白发生了什么事。我试过这个解决方案

但我们不希望超过 url。没有#,我们想要解决方案。 请提出适当的解决方案。 谢谢你的时间。

使用 angular cli 像这样构建您的应用程序。

ng build --prod --base-href /<project_name>/

.htaccess 中试试这个,让我知道它对我有用。

Put .htaccess in src folder (final path for is src/.htaccess) and give the file path in angular.json inside "assets"

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.html$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.html [L]
</IfModule>

您需要将 .htaccess 文件放在已部署项目的根目录下,即与 index.html 一起放置。下面是要写入上述文件的代码。

<IfModule mod_rewrite.c>
RewriteEngine on

# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Rewrite everything else to index.html
# to allow html5 state links
RewriteRule ^ index.html [L]

请看下图-