我有一个用 React 制作的网站,在 Digital Ocean 上运行 pm2 和 NGINX。入口点“/”加载得很好,但是当我尝试转到“/:用户名”路线时,我只是得到 404 Not Found。我的路由在 App.jsx 中定义如下:
<Switch>
<Route
exact path='/'
render={
routeProps => <Front {...routeProps} />
}
/>
<Route
path='/:username'
render={
routeProps => <Profile handleSignOut={ this.handleSignOut } {...routeProps} />
}
/>
</Switch>
Run Code Online (Sandbox Code Playgroud)
index.js 有以下代码:
ReactDOM.render(<BrowserRouter>
<App />
</BrowserRouter>,
document.getElementById('root')
)
Run Code Online (Sandbox Code Playgroud)
当在本地运行时,这些路由都按预期工作npm run start。