index.tsx
1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React from "react";
import { lazy } from 'react'
import { Navigate } from 'react-router-dom'
const Home = lazy(()=> import("@/views/Home/index"))
const Mine = lazy(()=> import("@/views/Mine/index"))
const Detail = lazy(()=> import("@/views/Detail/index"))
const Classify = lazy(()=> import("@/views/Classify/index"))
const Ranking = lazy(()=> import("@/views/Ranking/index"))
const Login = lazy(()=> import("@/views/Login/index"))
const WithLoadingComponent = (comp: any) => {
return (
<React.Suspense fallback={<div>Loading...</div>}>
{comp}
</React.Suspense>
)
}
const routers = [
{
path: '/',
element: <Navigate to="/login" />
},
{
path: "/login",
element: <Login />
},
{
path: "/",
element: <Home />,
children: [
{
path: "/detail",
element: WithLoadingComponent(<Detail />)
},
{
path: "/ranking",
element: WithLoadingComponent(<Ranking />)
},
{
path: "/mine",
element: WithLoadingComponent(<Mine />)
},
{
path: "/classify",
element: WithLoadingComponent(<Classify />)
}
]
},
]
export default routers