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 中会带有 #。根据你的需求和部署环境选择合适的路由模式。

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部