index.tsx 958 字节
import React, { lazy } from 'react'
import { Navigate } from 'react-router-dom'
import type { RouteObject } from 'react-router-dom'

const XX = lazy(() => import('@/views/discover/view/xx'))

// 路由懒加载
const Discover = lazy(() => import('@/views/discover'))
const ConsultationOrder = lazy(() => import('@/views/discover/view/ConsultationOrder'))
const Login = lazy(() => import('@/views/login'))

const loginState = Boolean(localStorage.getItem('token'))

const path = loginState ? '/discover' : '/login'

const routes: RouteObject[] = [
  { path: '/', element: <Navigate to={path} /> },
  { path: '/login', element: <Login /> },
  {
    path: '/discover',
    element: <Discover />,
    children: [
      { path: '/discover', element: <Navigate to={'/discover/ConsultationOrder'} /> },
      { path: '/discover/ConsultationOrder', element: <ConsultationOrder /> },
      { path: '/discover/xx', element: <XX /> }
    ]
  }
]

export default routes