我用react-router
创建了一个简单的应用程序,其部分如下:
<BrowserRouter>
<Switch>
<Route
exact
path="/"
render={() => <Redirect to="/home" />}
/>
{layoutRoutes.map((prop, key) => {
return (
<Route
path={prop.path}
component={prop.component}
key={key}
/>
);
})}
</Switch>
</BrowserRouter>
但是,当应用程序构建并部署到web服务器时,它会被呈现为一个白色页面,甚至不会重定向到/home
组件。
该应用程序本身是通过create-react-app
创建的,package.json
看起来如下所示:
{
"name": "front-end",
"version": "0.1.0",
"private": true,
"homepage": ".",
"dependencies": {
"bootstrap": "^4.3.1",
"formik": "^1.5.8",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-redux": "^7.1.1",
"react-router-dom": "^5.0.1",
"react-router-redux": "^4.0.8",
"react-scripts": "3.1.1",
"redux": "^4.0.4",
"redux-persist": "^6.0.0",
"redux-thunk": "^2.3.0",
"yup": "^0.27.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"json-server": "^0.15.1"
}
}
有任何线索吗?为什么要将开发环境作为npm start
来处理,而不是在构建和部署时?
发布于 2019-09-23 10:15:07
我发现这很有帮助:
如果使用Apache,则需要在公用文件夹中创建如下所示的
.htaccess
文件:
选项-MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.html QSA,L
当您运行npm run build
.时,它将被复制到npm run build
文件夹中。
https://stackoverflow.com/questions/58066075
复制相似问题