提交 29888d78 authored 作者: 王绍森's avatar 王绍森

修改路由

上级 873c7ec0
{ {
"name": "zunyi-nutrition", "name": "zunyi-nutrition",
"version": "0.1.0", "version": "0.1.0",
"homepage": "/yingyang",
"private": true, "private": true,
"dependencies": { "dependencies": {
"react": "^16.9.0", "react": "^16.9.0",
......
...@@ -11,6 +11,8 @@ import tomatoGetCmp from './pages/tomato/getComponent'; ...@@ -11,6 +11,8 @@ import tomatoGetCmp from './pages/tomato/getComponent';
import cornGetCmp from './pages/corn/getComponent'; import cornGetCmp from './pages/corn/getComponent';
import wheatGetCmp from './pages/wheat/getComponent'; import wheatGetCmp from './pages/wheat/getComponent';
const baseUrl = process.env.PUBLIC_URL;
const config = { const config = {
rape: { rape: {
elements: ['n', 'p', 'k', 'ga', 'mg', 'zn', 'b', 's'], elements: ['n', 'p', 'k', 'ga', 'mg', 'zn', 'b', 's'],
...@@ -42,7 +44,7 @@ const routes = Object.keys(config).reduce((acc, category) => { ...@@ -42,7 +44,7 @@ const routes = Object.keys(config).reduce((acc, category) => {
<Route <Route
key={category + '-' + element} key={category + '-' + element}
exact exact
path={`/${category}/lack-of-${element}`} path={`${baseUrl}/${category}/lack-of-${element}`}
component={Cmp} component={Cmp}
/> />
); );
...@@ -50,7 +52,7 @@ const routes = Object.keys(config).reduce((acc, category) => { ...@@ -50,7 +52,7 @@ const routes = Object.keys(config).reduce((acc, category) => {
<Route <Route
key={category + '-' + element + '-info'} key={category + '-' + element + '-info'}
exact exact
path={`/${category}/lack-of-${element}/info`} path={`${baseUrl}/${category}/lack-of-${element}/info`}
component={() => <InfoCmp category={category} element={element} />} component={() => <InfoCmp category={category} element={element} />}
/> />
); );
...@@ -65,11 +67,11 @@ function App() { ...@@ -65,11 +67,11 @@ function App() {
return ( return (
<Router> <Router>
<Switch> <Switch>
<Route exact path="/" component={Home} /> <Route exact path={baseUrl + "/"} component={Home} />
<Route exact path="/corn" component={Corn} /> <Route exact path={baseUrl + "/corn"} component={Corn} />
<Route exact path="/rape" component={Rape} /> <Route exact path={baseUrl + "/rape"} component={Rape} />
<Route exact path="/wheat" component={Wheat} /> <Route exact path={baseUrl + "/wheat"} component={Wheat} />
<Route exact path="/tomato" component={Tomato} /> <Route exact path={baseUrl + "/tomato"} component={Tomato} />
{ routes } { routes }
</Switch> </Switch>
</Router> </Router>
......
...@@ -7,6 +7,8 @@ import BackImg from '../仿真软件-植物营养元素缺素症切图/通用/ ...@@ -7,6 +7,8 @@ import BackImg from '../仿真软件-植物营养元素缺素症切图/通用/
import HomeImg from '../仿真软件-植物营养元素缺素症切图/通用/主页.png'; import HomeImg from '../仿真软件-植物营养元素缺素症切图/通用/主页.png';
import { convertpx2vw } from '../config'; import { convertpx2vw } from '../config';
const baseUrl = process.env.PUBLIC_URL;
const StyledNavBtn = styled(AnimatedBtn)` const StyledNavBtn = styled(AnimatedBtn)`
bottom: ${convertpx2vw(23)}; bottom: ${convertpx2vw(23)};
position: absolute; position: absolute;
...@@ -27,7 +29,7 @@ const BackBtn = withRouter(({ history }) => { ...@@ -27,7 +29,7 @@ const BackBtn = withRouter(({ history }) => {
return <StyledBackBtn bg={BackImg} to="#" onClick={e => handleClick(e)} /> return <StyledBackBtn bg={BackImg} to="#" onClick={e => handleClick(e)} />
}); });
const HomeBtn = () => <StyledHomeBtn bg={HomeImg} to="/" /> const HomeBtn = () => <StyledHomeBtn bg={HomeImg} to={baseUrl+'/'} />
export default function BGWithNavBtn({ className, children, bg }) { export default function BGWithNavBtn({ className, children, bg }) {
return ( return (
......
...@@ -8,6 +8,8 @@ import tomatoImg from '../仿真软件-植物营养元素缺素症切图/首页/ ...@@ -8,6 +8,8 @@ import tomatoImg from '../仿真软件-植物营养元素缺素症切图/首页/
import AnimatedBtn from '../components/AnimatedBtn'; import AnimatedBtn from '../components/AnimatedBtn';
import { convertpx2vw } from '../config'; import { convertpx2vw } from '../config';
const baseUrl = process.env.PUBLIC_URL;
const Container = styled(BackGround)` const Container = styled(BackGround)`
display: flex; display: flex;
flex-direction: row; flex-direction: row;
...@@ -22,10 +24,10 @@ const StyledBtn = styled(AnimatedBtn)` ...@@ -22,10 +24,10 @@ const StyledBtn = styled(AnimatedBtn)`
export default function Home() { export default function Home() {
return ( return (
<Container> <Container>
<StyledBtn bg={CornImg} to='/corn' /> <StyledBtn bg={CornImg} to={baseUrl + '/corn'}/>
<StyledBtn bg={WheatImg} to='/wheat' /> <StyledBtn bg={WheatImg} to={baseUrl + '/wheat'} />
<StyledBtn bg={RapeImg} to='/rape' /> <StyledBtn bg={RapeImg} to={baseUrl + '/rape'}/>
<StyledBtn bg={tomatoImg} to='/tomato' /> <StyledBtn bg={tomatoImg} to={baseUrl + '/tomato'} />
</Container> </Container>
); );
} }
\ No newline at end of file
...@@ -14,6 +14,8 @@ import LackPBtnBg from '../../仿真软件-植物营养元素缺素症切图/1 ...@@ -14,6 +14,8 @@ import LackPBtnBg from '../../仿真软件-植物营养元素缺素症切图/1
import LackKBtnBg from '../../仿真软件-植物营养元素缺素症切图/1玉米/缺钾.png' import LackKBtnBg from '../../仿真软件-植物营养元素缺素症切图/1玉米/缺钾.png'
import LackZnBtnBg from '../../仿真软件-植物营养元素缺素症切图/1玉米/缺锌.png' import LackZnBtnBg from '../../仿真软件-植物营养元素缺素症切图/1玉米/缺锌.png'
const baseUrl = process.env.PUBLIC_URL;
const bgs = [ const bgs = [
LackNBg, LackPBg, LackKBg, LackZnBg, LackBBg LackNBg, LackPBg, LackKBg, LackZnBg, LackBBg
] ]
...@@ -37,7 +39,7 @@ export default function (idx) { ...@@ -37,7 +39,7 @@ export default function (idx) {
} }
const cornList = ['n', 'p', 'k', 'zn', 'b']; const cornList = ['n', 'p', 'k', 'zn', 'b'];
config.btns.rows[0][idx].correct = true; config.btns.rows[0][idx].correct = true;
config.btns.rows[0].forEach((ele, i) => ele.to = `/corn/lack-of-${cornList[i]}/info`); config.btns.rows[0].forEach((ele, i) => ele.to = `${baseUrl}/corn/lack-of-${cornList[i]}/info`);
return <CheckLack config={config} />; return <CheckLack config={config} />;
}); });
return Component; return Component;
......
...@@ -20,6 +20,8 @@ import LackKBtnBg from '../../仿真软件-植物营养元素缺素症切图/3 ...@@ -20,6 +20,8 @@ import LackKBtnBg from '../../仿真软件-植物营养元素缺素症切图/3
import LackZnBtnBg from '../../仿真软件-植物营养元素缺素症切图/3油菜/缺锌.png' import LackZnBtnBg from '../../仿真软件-植物营养元素缺素症切图/3油菜/缺锌.png'
import LackMgBtnBg from '../../仿真软件-植物营养元素缺素症切图/3油菜/缺镁.png' import LackMgBtnBg from '../../仿真软件-植物营养元素缺素症切图/3油菜/缺镁.png'
const baseUrl = process.env.PUBLIC_URL;
const bgs = [ const bgs = [
[ [
LackNBg, LackPBg, LackKBg, LackGaBg LackNBg, LackPBg, LackKBg, LackGaBg
...@@ -56,7 +58,7 @@ export default function (lackElement) { ...@@ -56,7 +58,7 @@ export default function (lackElement) {
config.btns.rows[lackElement[0]][lackElement[1]].correct = true; config.btns.rows[lackElement[0]][lackElement[1]].correct = true;
config.btns.rows.forEach((r, i) => { config.btns.rows.forEach((r, i) => {
r.forEach((ele, j) => { r.forEach((ele, j) => {
ele.to = `/rape/lack-of-${rapeList[i][j]}/info` ele.to = `${baseUrl}/rape/lack-of-${rapeList[i][j]}/info`
}); });
}); });
return <CheckLack config={config} />; return <CheckLack config={config} />;
......
...@@ -22,6 +22,8 @@ import LackPBtnBg from '../../仿真软件-植物营养元素缺素症切图/4 ...@@ -22,6 +22,8 @@ import LackPBtnBg from '../../仿真软件-植物营养元素缺素症切图/4
import LackMgBtnBg from '../../仿真软件-植物营养元素缺素症切图/4西红柿/缺镁.png' import LackMgBtnBg from '../../仿真软件-植物营养元素缺素症切图/4西红柿/缺镁.png'
import LackMuBtnBg from '../../仿真软件-植物营养元素缺素症切图/4西红柿/缺钼.png' import LackMuBtnBg from '../../仿真软件-植物营养元素缺素症切图/4西红柿/缺钼.png'
const baseUrl = process.env.PUBLIC_URL;
const bgs = [ const bgs = [
LackNBg, LackPBg, LackKBg, LackGaBg, LackMgBg, LackZnBg, LackBBg, LackSBg, LackMuBg, LackNBg, LackPBg, LackKBg, LackGaBg, LackMgBg, LackZnBg, LackBBg, LackSBg, LackMuBg,
]; ];
...@@ -46,7 +48,7 @@ export default function(idx) { ...@@ -46,7 +48,7 @@ export default function(idx) {
config.btns.rows[0][idx].correct = true; config.btns.rows[0][idx].correct = true;
const tomatoList = ['n', 'p', 'k', 'ga', 'mg', 'zn', 'b', 's', 'mu']; const tomatoList = ['n', 'p', 'k', 'ga', 'mg', 'zn', 'b', 's', 'mu'];
config.btns.rows[0].forEach((ele, i) => { config.btns.rows[0].forEach((ele, i) => {
ele.to = `/tomato/lack-of-${tomatoList[i]}/info` ele.to = `${baseUrl}/tomato/lack-of-${tomatoList[i]}/info`
}); });
return <CheckLack config={config} />; return <CheckLack config={config} />;
}); });
......
...@@ -24,6 +24,8 @@ import Mg_Btn_Bg from '../../仿真软件-植物营养元素缺素症切图/2小 ...@@ -24,6 +24,8 @@ import Mg_Btn_Bg from '../../仿真软件-植物营养元素缺素症切图/2小
const bgs = [ N_Bg, P_Bg, K_Bg, Ga_Bg, Mg_Bg, Zn_Bg, B_Bg, Mn_Bg, Fe_Bg, ] const bgs = [ N_Bg, P_Bg, K_Bg, Ga_Bg, Mg_Bg, Zn_Bg, B_Bg, Mn_Bg, Fe_Bg, ]
const baseUrl = process.env.PUBLIC_URL;
export default function (idx) { export default function (idx) {
const Component = withRouter(({ match }) => { const Component = withRouter(({ match }) => {
const to = match.url+'/info' const to = match.url+'/info'
...@@ -45,7 +47,7 @@ export default function (idx) { ...@@ -45,7 +47,7 @@ export default function (idx) {
config.btns.rows[0][idx].correct = true; config.btns.rows[0][idx].correct = true;
const wheatList = ['n', 'p', 'k', 'ga', 'mg', 'zn', 'b', 'mn', 'fe']; const wheatList = ['n', 'p', 'k', 'ga', 'mg', 'zn', 'b', 'mn', 'fe'];
config.btns.rows[0].forEach((ele, i) => { config.btns.rows[0].forEach((ele, i) => {
ele.to = `/wheat/lack-of-${wheatList[i]}/info` ele.to = `${baseUrl}/wheat/lack-of-${wheatList[i]}/info`
}); });
return <CheckLack config={config} />; return <CheckLack config={config} />;
}); });
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论