【发布时间】:2018-10-26 20:31:25
【问题描述】:
我有一个使用 pm2 和 NGINX 在 Digital Ocean 上运行的 React 网站。入口点“/”加载得很好,但是当我尝试转到“/:username”路由时,我只得到 404 Not Found。我的路由在 App.jsx 中定义如下:
<Switch>
<Route
exact path='/'
render={
routeProps => <Front {...routeProps} />
}
/>
<Route
path='/:username'
render={
routeProps => <Profile handleSignOut={ this.handleSignOut } {...routeProps} />
}
/>
</Switch>
index.js 代码如下:
ReactDOM.render(<BrowserRouter>
<App />
</BrowserRouter>,
document.getElementById('root')
)
使用npm run start 在本地运行时,所有路由都按预期工作。
【问题讨论】:
-
您需要确保您的服务器为您的所有路由提供
index.html文件,以便 React Router 可以处理浏览器中的路由。
标签: reactjs nginx react-router pm2