Skip to content

[Docs] 建议在部署文档中补充 Web 服务器路由配置说明(解决 SPA 刷新 404 问题) #9

Description

@unkn0tted

我在将项目打包并部署到线上环境时,遇到了一个单页面应用(SPA)常见的路由问题:页面首次加载和内部点击跳转都正常,但只要在非根目录下刷新页面,或者直接通过 URL 访问某个具体路由,服务器就会返回 404。

虽然这是一个 History 路由模式下的基础现象,但对于不太熟悉服务器配置的开发者来说,可能会在这里卡住。

为了让新手能够更顺畅地部署本项目,建议在项目的 README.md 或官方文档的“部署”章节中,补充一段关于服务器配置的提示。

例如,针对 Nginx 用户,可以建议在配置文件的 location / 块中增加 try_files 指令:

location / {
# ... 其他配置 ...
try_files $uri $uri/ /index.html;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions