我有一个 React 应用程序,我的导航中有一个 404 问题,如果我尝试刷新一个不是根页面的页面,它会给我一个 404。
事情是它只发生在我身上而不是开发中。
在开发环境中,我使用npm start
,在生产环境中,我使用serve build
。
这使调试变得更加复杂,因为我失去了用于调试的热重载选项。每次进行更改时,我都必须编译我的 docker 镜像。
这是我的一些代码:
<BrowserRouter>
<div>
<Switch>
<Route exact path="/premiere-connexion" component={FirstLoginLayout}/>
{(user.state === "1" && window.location.pathname === "/premiere-connexion") &&
<Redirect to="/premiere-connexion"/>}
<PrivateRoute path="/bo" component={BackOfficeLayout} profiles={["ADMIN"]}/>
<Route exact path="/" component={Customer}/>
<Redirect to="/"/>
</Switch>
}
</div>
</BrowserRouter>
知道我应该如何在本地复制它吗?
最佳答案
根据@hbentlov 的建议,我解决了这个问题,在 public/
文件夹中创建了一个文件 serve.json
,内容如下:
{
"rewrites": [{
"source": "**",
"destination": "/index.html"
}]
}
关于reactjs - React 应用程序将在产品刷新页面上给出 404,但在开发中不会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56182592/