Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZunYiYuanSuQueFaZhen
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
仿真软件web页面
ZunYiYuanSuQueFaZhen
Commits
873c7ec0
提交
873c7ec0
authored
8月 24, 2019
作者:
王绍森
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
去掉重复的路由
上级
47718a30
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
47 行增加
和
82 行删除
+47
-82
App.js
src/App.js
+47
-82
没有找到文件。
src/App.js
浏览文件 @
873c7ec0
...
@@ -11,13 +11,55 @@ import tomatoGetCmp from './pages/tomato/getComponent';
...
@@ -11,13 +11,55 @@ 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
rapeList
=
[
'n'
,
'p'
,
'k'
,
'ga'
,
'mg'
,
'zn'
,
'b'
,
's'
];
const
config
=
{
rape
:
{
elements
:
[
'n'
,
'p'
,
'k'
,
'ga'
,
'mg'
,
'zn'
,
'b'
,
's'
],
getCmp
:
rapeGetComponent
,
idxFormater
:
idx
=>
[
Math
.
floor
(
idx
/
4
),
idx
%
4
],
},
const
tomatoList
=
[
'n'
,
'p'
,
'k'
,
'ga'
,
'mg'
,
'zn'
,
'b'
,
's'
,
'mu'
];
tomato
:
{
elements
:
[
'n'
,
'p'
,
'k'
,
'ga'
,
'mg'
,
'zn'
,
'b'
,
's'
,
'mu'
],
getCmp
:
tomatoGetCmp
,
},
const
cornList
=
[
'n'
,
'p'
,
'k'
,
'zn'
,
'b'
];
corn
:
{
elements
:
[
'n'
,
'p'
,
'k'
,
'zn'
,
'b'
],
getCmp
:
cornGetCmp
,
},
wheat
:
{
elements
:
[
'n'
,
'p'
,
'k'
,
'ga'
,
'mg'
,
'zn'
,
'b'
,
'mn'
,
'fe'
],
getCmp
:
wheatGetCmp
,
},
}
const
routes
=
Object
.
keys
(
config
).
reduce
((
acc
,
category
)
=>
{
const
curRoutes
=
[];
const
{
elements
,
getCmp
,
idxFormater
}
=
config
[
category
];
elements
.
forEach
((
element
,
idx
)
=>
{
const
Cmp
=
getCmp
(
idxFormater
?
idxFormater
(
idx
)
:
idx
);
curRoutes
.
push
(
<
Route
key
=
{
category
+
'-'
+
element
}
exact
path
=
{
`/
${
category
}
/lack-of-
${
element
}
`
}
component
=
{
Cmp
}
/
>
);
curRoutes
.
push
(
<
Route
key
=
{
category
+
'-'
+
element
+
'-info'
}
exact
path
=
{
`/
${
category
}
/lack-of-
${
element
}
/info`
}
component
=
{()
=>
<
InfoCmp
category
=
{
category
}
element
=
{
element
}
/>
}
/>
);
});
return
acc
.
concat
(
curRoutes
);
},
[]);
console
.
log
(
routes
);
const
wheatList
=
[
'n'
,
'p'
,
'k'
,
'ga'
,
'mg'
,
'zn'
,
'b'
,
'mn'
,
'fe'
];
function
App
()
{
function
App
()
{
return
(
return
(
...
@@ -28,84 +70,7 @@ function App() {
...
@@ -28,84 +70,7 @@ function App() {
<
Route
exact
path
=
"/rape"
component
=
{
Rape
}
/
>
<
Route
exact
path
=
"/rape"
component
=
{
Rape
}
/
>
<
Route
exact
path
=
"/wheat"
component
=
{
Wheat
}
/
>
<
Route
exact
path
=
"/wheat"
component
=
{
Wheat
}
/
>
<
Route
exact
path
=
"/tomato"
component
=
{
Tomato
}
/
>
<
Route
exact
path
=
"/tomato"
component
=
{
Tomato
}
/
>
{
{
routes
}
rapeList
.
map
((
name
,
idx
)
=>
{
const
Cmp
=
rapeGetComponent
([
Math
.
floor
(
idx
/
4
),
idx
%
4
]);
return
(
<
Route
key
=
{
'rape-'
+
name
}
exact
path
=
{
'/rape/lack-of-'
+
name
}
component
=
{
Cmp
}
/
>
);
})
}
{
rapeList
.
map
(
name
=>
(
<
Route
key
=
{
'rape'
+
name
+
'info'
}
exact
path
=
{
'/rape/lack-of-'
+
name
+
'/info'
}
component
=
{()
=>
<
InfoCmp
category
=
'rape'
element
=
{
name
}
/>
}
/>
))
}
{
tomatoList
.
map
((
name
,
idx
)
=>
(
<
Route
exact
key
=
{
'tomato-'
+
name
}
path
=
{
'/tomato/lack-of-'
+
name
}
component
=
{
tomatoGetCmp
(
idx
)}
/
>
))
}
{
tomatoList
.
map
((
name
,
idx
)
=>
(
<
Route
exact
key
=
{
'tomato-'
+
name
+
'info'
}
path
=
{
'/tomato/lack-of-'
+
name
+
'/info'
}
component
=
{()
=>
<
InfoCmp
category
=
'tomato'
element
=
{
name
}
/>
}
/>
))
}
{
cornList
.
map
((
name
,
idx
)
=>
(
<
Route
exact
key
=
{
'corn-'
+
name
}
path
=
{
'/corn/lack-of-'
+
name
}
component
=
{
cornGetCmp
(
idx
)}
/
>
))
}
{
cornList
.
map
((
name
,
idx
)
=>
(
<
Route
exact
key
=
{
'corn-'
+
name
+
'info'
}
path
=
{
'/corn/lack-of-'
+
name
+
'/info'
}
component
=
{()
=>
<
InfoCmp
category
=
'corn'
element
=
{
name
}
/>
}
/>
))
}
{
wheatList
.
map
((
name
,
idx
)
=>
(
<
Route
exact
key
=
{
'wheat-'
+
name
}
path
=
{
'/wheat/lack-of-'
+
name
}
component
=
{
wheatGetCmp
(
idx
)}
/
>
))
}
{
wheatList
.
map
((
name
,
idx
)
=>
(
<
Route
exact
key
=
{
'wheat-'
+
name
+
'info'
}
path
=
{
'/wheat/lack-of-'
+
name
+
'/info'
}
component
=
{()
=>
<
InfoCmp
category
=
'wheat'
element
=
{
name
}
/>
}
/>
))
}
<
/Switch
>
<
/Switch
>
<
/Router
>
<
/Router
>
);
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论