diff --git a/src/router/RouteInterception.tsx b/src/router/RouteInterception.tsx
index 660baf2..49b17e1 100644
--- a/src/router/RouteInterception.tsx
+++ b/src/router/RouteInterception.tsx
@@ -1,6 +1,9 @@
import { Navigate } from "react-router-dom"
import Notfound from "../Notfound"
import { getToken } from "../utils/auth"
+import { useDispatch, useSelector } from "react-redux"
+import { addRoutes, getAsyncRouters } from "../stores/permission"
+import { addAuthInfo, getAuthInfo } from "../stores/auth"
const Views = import.meta.glob('../view/**/*.tsx')
// 判断是否有对应路径的映射文件
@@ -13,17 +16,35 @@ const hasMapFile = (filePath: string): boolean => {
* @description 路由拦截组件
* @param {children: ReactDOM, filePath: string(文件路径)}
*/
-export default function RouteInterception ({children, filePath=""}: any) {
- if(getToken()) {
- if(filePath!=="") {
- if(hasMapFile(filePath)) {
- return children
- } else {
- return
+export default function RouteInterception({ children, filePath = "" }: any) {
+ const routes: [] = useSelector((store: any) => store.permission)
+ const dispatch = useDispatch()
+
+ const requestAsyncRoutes = async () => {
+ const { payload } = await dispatch(getAsyncRouters() as any)
+ dispatch(addRoutes(payload))
+ }
+
+ const requestAuthInfo = async () => {
+ const {payload} = await dispatch(getAuthInfo() as any)
+ dispatch(addAuthInfo(payload))
+ }
+
+ if (getToken()) {
+ if (!routes.length) {
+ requestAsyncRoutes()
+ requestAuthInfo()
+ } else {
+ if (filePath !== "") {
+ if (hasMapFile(filePath)) {
+ return children
+ } else {
+ return
+ }
}
+ return children
}
- return children
} else {
- return
+ return
}
}
\ No newline at end of file