首先,我的应用程序在localhost上运行良好。除NotFound(404)页面外,每个组件和URL均可在服务器上工作。
<Switch>
<Route
exact
path={'/'}
render={() => (
{/*something here*/}
)} />
<Route
exact
path={'/secondPage'}
render={() => (
{/*something here*/}
)} />
<Route
path={'*'}
render={() => (
<NotFound />
)} />
</Switch>
我还尝试了<Route render={() => ( <NotFound /> )} />
Index.js:
ReactDOM.render(
<BrowserRouter basename={process.env.PUBLIC_URL}><App /></BrowserRouter>,
document.getElementById('root')
)
我试图像部署到GitHub页面一样部署React应用。这是我的package.json
{
"homepage": "https://mywebsite.com/react-app/",
"dependencies": {
"escape-string-regexp": "^1.0.5",
"lodash": "^4.17.10",
"prop-types": "^15.6.1",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"react-router-dom": "^4.3.1",
"sort-by": "^1.2.0"
},
"devDependencies": {
"gh-pages": "^1.2.0",
"react-scripts": "1.1.4"
},
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
我想念什么?