Nginx 服务器配置,如果你使用 Nginx 作为 Web 服务器,你需要在你的 Nginx 配置文件中添加一个 try_files 指令。
server {
listen 80;
server_name yoursite.com;
location / {
# 尝试寻找文件,如果找不到,就返回 index.html
try_files $uri $uri/ /index.html;
}
}
Apache 服务器配置,如果你使用 Apache,你需要在你的项目根目录下创建一个 .htaccess 文件,并添加以下内容。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
history 模式提供更美观的 URL,但需要服务器的额外配置;而 hash 模式不需要服务器配置,但 URL 中会带有 #。根据你的需求和部署环境选择合适的路由模式。

发表评论 取消回复