React Router 在生产中出现 404 错误

Sch*_*cke 6 javascript reactjs react-router

React Router 适用于本地计算机、Chrome,但不适用于 safari 和其他浏览器,

 <Switch>
    <Route exact path={"/"} component={Home} />
    <Route path="/programs/:slug" component={Programs} />
    <Route path="/page/:slug" component={Page} />
    <Route component={NotFound} />
</Switch>
Run Code Online (Sandbox Code Playgroud)

这是我的代码,但它在开发模式下完美运行,没有错误,但在生产中,当我导航到programs/:slug 或 page/:slug 时,safari 给出 404 错误

Sch*_*cke 9

我将其添加到 .htaccess

RewriteBase /
RewriteCond %{REQUEST_URI} !^/(assets/?|$)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
Run Code Online (Sandbox Code Playgroud)

感谢 Kishan Mundha 的解释


Kis*_*dha 2

您可能需要在服务器上配置单个入口点index.html。所有 url 都应定位到index.html,入口点将根据路由决定如何呈现和内容。