【发布时间】:2020-05-03 22:47:09
【问题描述】:
当我在 localhost 中工作时,使用 create-react-app
我可以访问 localhost:3000/A 或 localhost:3000/B
但是当我将它部署到服务器时,npm build run 并将构建的文件放到服务器文件夹中,例如 https://ip/project_name
我可以点击<Link/> 转到https://ip/project_name/A 或https://ip/project_name/B
但我无法直接访问https://ip/project_name/A。
App.js
<BrowserRouter basename={'project_name'}>
<Route path='/A' component={A}/>
<Route path='/B' component={B}/>
</BrowserRouter>
链接
<Link to="/A">A</Link>
<Link to="/B">B</Link>
package.json
"homepage": ".",
...
"dependencies": {
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-router-dom": "^5.1.2",
"react-scripts": "3.2.0"
}
【问题讨论】:
标签: reactjs routes react-router web-deployment webdeploy