53 lines
1.1 KiB
TypeScript
53 lines
1.1 KiB
TypeScript
import LayOut from '../layout/index'
|
|
import { Suspense, lazy } from 'react'
|
|
import Loading from '../Loading'
|
|
import RouteInterception from './RouteInterception'
|
|
import Notfound from '../Notfound'
|
|
// interface Meta {
|
|
// title: string,
|
|
// redirect?: boolean
|
|
// }
|
|
|
|
type route = {
|
|
path: string,
|
|
element: any,
|
|
meta?: any,
|
|
children?: Array<route>
|
|
}
|
|
|
|
const lazyLoad = (viewName: string) => {
|
|
if(viewName === 'login') {
|
|
const LoginView = lazy(()=>import('../Login'))
|
|
return <LoginView />
|
|
}
|
|
if(viewName === 'home') {
|
|
const Home = lazy(()=>import('../view/home'))
|
|
return <Home />
|
|
}
|
|
const View = lazy(()=>import(`../view/${viewName}.tsx`))
|
|
return <View/>
|
|
}
|
|
|
|
// 常驻路由
|
|
const currentRouter: Array<route> = [
|
|
{
|
|
path: '/',
|
|
element: <RouteInterception><LayOut /></RouteInterception>,
|
|
children: [
|
|
{
|
|
path: "", //登录后默认跳转路径
|
|
element : <Suspense fallback={<Loading />}>{lazyLoad('home')}</Suspense>
|
|
},
|
|
{
|
|
path: "*",
|
|
element: <Notfound />
|
|
}
|
|
]
|
|
},
|
|
{
|
|
path: '/login',
|
|
element: lazyLoad('login')
|
|
}
|
|
]
|
|
|
|
export default currentRouter |