温华: 配置stores终端缓存黑名单
This commit is contained in:
29
src/router/RouteInterception.tsx
Normal file
29
src/router/RouteInterception.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Navigate } from "react-router-dom"
|
||||
import Notfound from "../Notfound"
|
||||
import { getToken } from "../utils/auth"
|
||||
|
||||
const Views = import.meta.glob('../view/**/*.tsx')
|
||||
// 判断是否有对应路径的映射文件
|
||||
const hasMapFile = (filePath: string): boolean => {
|
||||
return Views[`../view/${filePath}.tsx`] ? true : false
|
||||
}
|
||||
|
||||
/**
|
||||
* @author {温华}
|
||||
* @description 路由拦截组件
|
||||
* @param {children: ReactDOM, filePath: string(文件路径)}
|
||||
*/
|
||||
export default function RouteInterception ({children, filePath=""}: any) {
|
||||
if(getToken()) {
|
||||
if(filePath!=="") {
|
||||
if(hasMapFile(filePath)) {
|
||||
return children
|
||||
} else {
|
||||
return <Notfound />
|
||||
}
|
||||
}
|
||||
return children
|
||||
} else {
|
||||
return <Navigate to='/login' />
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,8 @@ import { getToken } from '../utils/auth'
|
||||
import LayOut from '../layout/index'
|
||||
import Home from '../view/home'
|
||||
import { Suspense, lazy } from 'react'
|
||||
import { Navigate } from 'react-router-dom'
|
||||
import Loading from '../Loading'
|
||||
import Notfound from '../Notfound'
|
||||
const Views = import.meta.glob('../view/**/*.tsx')
|
||||
import RouteInterception from './RouteInterception'
|
||||
interface Meta {
|
||||
title: string,
|
||||
redirect?: boolean
|
||||
@@ -27,29 +25,6 @@ const lazyLoad = (viewName: string) => {
|
||||
return <View/>
|
||||
}
|
||||
|
||||
// 判断是否有对应路径的映射文件
|
||||
const hasMapFile = (filePath: string): boolean => {
|
||||
let flag: boolean = false
|
||||
Views[`../view/${filePath}.tsx`] ? flag = true : flag = false
|
||||
return flag
|
||||
}
|
||||
|
||||
// 路由拦截
|
||||
export const RouteInterception = ({children, filePath=""}: any) => {
|
||||
if(getToken()) {
|
||||
if(filePath!=="") {
|
||||
if(hasMapFile(filePath)) {
|
||||
return children
|
||||
} else {
|
||||
return <Notfound />
|
||||
}
|
||||
}
|
||||
return children
|
||||
} else {
|
||||
return <Navigate to='/login' />
|
||||
}
|
||||
}
|
||||
|
||||
// 常驻路由
|
||||
const currentRouter: Array<route> = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user