import { useRoutes, Navigate } from 'react-router-dom' import { lazy, Suspense } from 'react' const Login = lazy(() => import('./views/login/Index')) const Layout = lazy(() => import('./views/layout/Index')) const UserList = lazy(() => import('./views/user/Index')) const MovieList = lazy(() => import('./views/movie/Index')) const MovieAdd = lazy(() => import('./views/movie/add')) // 异步加载lazy需要组合Suspense包裹使用 function elem(dom: any) { return ( {dom} ) } export default () => { const routes = useRoutes([ { path: '/login', element: }, { path: '/', element: , children: [ { path: '/', element: , errorElement: (
出错了!
) }, { path: 'userlist', element: elem(), errorElement: (
出错了!
) }, { path: 'movielist', element: elem() }, { path: 'movieAdd', element: elem() } ] }, { path: '*', element: (
404
) } ]) return (routes) }