在 Apache 的配置文件中添加 rewrite 规则来解决此问题。具体步骤如下:
打开 Apache 的配置文件,一般在 /etc/httpd/conf/httpd.conf 或 /etc/httpd/conf.d/ 下,可以用命令进行查找。
在配置文件的末尾添加以下代码:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.html [L,QSA]
以上代码中,RewriteRule 指定了所有非文件请求都重定向到 index.html。这样就可以在使用 Angular 路由时避免“文件未找到”错误的问题了。