Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
center-book
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
center-book
Commits
18db76fd
提交
18db76fd
authored
6月 17, 2024
作者:
王鹏飞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: update
上级
08c9ee29
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
33 行增加
和
32 行删除
+33
-32
App.jsx
src/App.jsx
+2
-2
index.jsx
src/layout/index.jsx
+2
-2
baseRouter.jsx
src/routes/baseRouter.jsx
+3
-3
index.jsx
src/routes/index.jsx
+26
-25
没有找到文件。
src/App.jsx
浏览文件 @
18db76fd
...
@@ -3,7 +3,7 @@ import { ErrorBoundary } from 'react-error-boundary'
...
@@ -3,7 +3,7 @@ import { ErrorBoundary } from 'react-error-boundary'
import
{
Button
}
from
'antd'
import
{
Button
}
from
'antd'
import
'./App.less'
import
'./App.less'
import
{
Get
routesDy
amic
}
from
'@/routes/index'
import
{
Get
RoutesDyn
amic
}
from
'@/routes/index'
function
fallbackRender
({
error
,
resetErrorBoundary
})
{
function
fallbackRender
({
error
,
resetErrorBoundary
})
{
return
(
return
(
...
@@ -20,7 +20,7 @@ function App() {
...
@@ -20,7 +20,7 @@ function App() {
return
(
return
(
<
ErrorBoundary
fallbackRender=
{
fallbackRender
}
>
<
ErrorBoundary
fallbackRender=
{
fallbackRender
}
>
<
Suspense
>
<
Suspense
>
<
Get
routesDy
amic
/>
<
Get
RoutesDyn
amic
/>
</
Suspense
>
</
Suspense
>
</
ErrorBoundary
>
</
ErrorBoundary
>
)
)
...
...
src/layout/index.jsx
浏览文件 @
18db76fd
...
@@ -18,7 +18,7 @@ import { generateToAntdMenus } from '@/utils/breadCrumb'
...
@@ -18,7 +18,7 @@ import { generateToAntdMenus } from '@/utils/breadCrumb'
const
{
Header
,
Content
}
=
Layout
const
{
Header
,
Content
}
=
Layout
function
generateMenus
(
items
=
[],
maxLevel
=
2
,
level
=
1
)
{
function
generateMenus
(
items
=
[],
maxLevel
=
2
,
level
=
1
)
{
return
items
.
map
(
item
=>
{
return
items
.
map
(
(
item
)
=>
{
const
children
=
level
<
maxLevel
&&
item
.
childs
?
generateMenus
(
item
.
childs
,
maxLevel
,
level
+
1
)
:
null
const
children
=
level
<
maxLevel
&&
item
.
childs
?
generateMenus
(
item
.
childs
,
maxLevel
,
level
+
1
)
:
null
return
{
key
:
item
.
id
+
''
,
path
:
item
.
front_url
,
label
:
<
Link
to=
{
item
.
front_url
}
>
{
item
.
name
}
</
Link
>,
children
}
return
{
key
:
item
.
id
+
''
,
path
:
item
.
front_url
,
label
:
<
Link
to=
{
item
.
front_url
}
>
{
item
.
name
}
</
Link
>,
children
}
})
})
...
@@ -50,7 +50,7 @@ export default function AppLayout() {
...
@@ -50,7 +50,7 @@ export default function AppLayout() {
}
}
useEffect
(()
=>
{
useEffect
(()
=>
{
(
async
()
=>
{
;
(
async
()
=>
{
await
getSSOToken
()
await
getSSOToken
()
await
getMenu
()
await
getMenu
()
})()
})()
...
...
src/routes/baseRouter.jsx
浏览文件 @
18db76fd
import
{
lazy
}
from
'react'
import
{
lazy
}
from
'react'
import
{
Navigate
}
from
'react-router-dom'
//
import { Navigate } from 'react-router-dom'
import
{
authComponent
}
from
'./lazyLoadAndDelay'
// 添加一个固定的延迟时间,以便你可以看到加载状态
import
{
authComponent
}
from
'./lazyLoadAndDelay'
// 添加一个固定的延迟时间,以便你可以看到加载状态
import
Layout
from
'@/layout/index'
import
Layout
from
'@/layout/index'
...
@@ -24,8 +24,8 @@ const baseRouter = [
...
@@ -24,8 +24,8 @@ const baseRouter = [
Component
:
lazy
(()
=>
import
(
'@/pages/user-module/login'
))
Component
:
lazy
(()
=>
import
(
'@/pages/user-module/login'
))
}
}
]
]
}
,
}
{
path
:
'*'
,
element
:
<
Navigate
to=
"/"
/>
}
//
{ path: '*', element: <Navigate to="/" /> }
]
]
export
default
baseRouter
export
default
baseRouter
src/routes/index.jsx
浏览文件 @
18db76fd
import
{
useEffect
}
from
'react'
;
import
{
useEffect
}
from
'react'
import
{
useRoutes
,
Navigate
}
from
'react-router-dom'
;
import
{
useRoutes
,
Navigate
}
from
'react-router-dom'
import
{
filterAsyncRouter
}
from
'./lazyLoadAndDelay'
;
import
{
filterAsyncRouter
}
from
'./lazyLoadAndDelay'
import
{
useSelector
}
from
'react-redux'
;
import
{
useSelector
}
from
'react-redux'
import
baseRouter
from
'./baseRouter'
;
import
baseRouter
from
'./baseRouter'
const
addDefaultNavigation
=
(
menuRoutes
)
=>
{
const
addDefaultNavigation
=
(
menuRoutes
)
=>
{
menuRoutes
.
forEach
((
item
)
=>
{
menuRoutes
.
forEach
((
item
)
=>
{
const
children
=
item
.
children
;
const
children
=
item
.
children
if
(
children
&&
children
.
length
>
0
)
{
if
(
children
&&
children
.
length
>
0
)
{
// 如果有子项,递归调用 addDefaultNavigation
// 如果有子项,递归调用 addDefaultNavigation
addDefaultNavigation
(
children
)
;
addDefaultNavigation
(
children
)
// 在 children 数组的开头添加默认导航项
// 在 children 数组的开头添加默认导航项
children
.
unshift
({
children
.
unshift
({
index
:
true
,
index
:
true
,
element
:
<
Navigate
to=
{
children
[
0
].
path
}
/>
,
element
:
<
Navigate
to=
{
children
[
0
].
path
}
/>
})
;
})
}
}
})
;
})
return
menuRoutes
;
return
menuRoutes
}
;
}
const
Get
routesDy
amic
=
()
=>
{
const
Get
RoutesDyn
amic
=
()
=>
{
// 合并路由
// 合并路由
const
{
menuRouter
}
=
useSelector
((
state
)
=>
state
.
user
)
;
const
{
menuRouter
}
=
useSelector
((
state
)
=>
state
.
user
)
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
menuRouter
?.
length
)
{
if
(
menuRouter
?.
length
)
{
const
menuRoutes
=
filterAsyncRouter
(
menuRouter
)
;
const
menuRoutes
=
filterAsyncRouter
(
menuRouter
)
const
hasRoute
=
baseRouter
[
0
].
children
;
const
hasRoute
=
baseRouter
[
0
].
children
const
newMenus
=
addDefaultNavigation
(
menuRoutes
)
;
const
newMenus
=
addDefaultNavigation
(
menuRoutes
)
const
firstObj
=
{
const
firstObj
=
{
index
:
true
,
index
:
true
,
element
:
<
Navigate
to=
{
newMenus
[
0
].
path
}
/>
,
element
:
<
Navigate
to=
{
newMenus
[
0
].
path
}
/>
}
;
}
baseRouter
[
0
].
children
=
[
firstObj
,
...
newMenus
,
...
hasRoute
]
;
baseRouter
[
0
].
children
=
[
firstObj
,
...
newMenus
,
...
hasRoute
]
}
}
},
[
menuRouter
]);
},
[
menuRouter
])
const
element
=
useRoutes
(
baseRouter
);
console
.
log
(
baseRouter
)
const
element
=
useRoutes
(
baseRouter
)
return
<>
{
element
}
</>
;
return
<>
{
element
}
</>
}
;
}
export
{
Get
routesDyamic
};
export
{
Get
RoutesDynamic
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论