Skip to content

react-router 指定路由浏览器中单页面刷新404问题 #1

@timi-black

Description

@timi-black

当直接从页面入口路由逐个点击链接时,没问题

image

当在当前页面刷新浏览器页面时情况如下

image

  • 原因
    nginx会试图在/react/test/snacks目录下找index.html,404是肯定的。此时需要设置一个代理如下

location / {
root "D:/测试";
index index.html index.htm;
}
location /react/test/ {
try_files $uri /react/test/index.html;
root "D:/测试";
}

参考地址: http://yjph83.iteye.com/blog/2311687

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions