我正在使用 react-router
来组织具有以下结构的 Web 应用程序:
<Router history={createBrowserHistory()}>
<Route path="/" component={AnyPic}>
<IndexRoute component={PhotoList} />
<Route path="p/:photoId" component={PhotoView} />
</Route>
</Router>
这工作正常,但我在直接链接到与 p/:photoId
匹配的 URL 时遇到问题。假设我的网页上加载了 localhost:8000/p/xyz
。如果我刷新页面或直接链接到该页面,则会收到 404
错误。我明白这是因为没有 p
目录。有什么办法可以解决这个问题吗?
最佳答案
您缺少 createBrowserHistory
的服务器端配置。请参阅文档 https://github.com/rackt/react-router/blob/v1.0.0/docs/guides/basics/Histories.md#configuring-your-server .
关于reactjs - 使用服务器配置react-router,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33926927/