如何在React18中正确引入react-router-dom6呢?本文告诉你

import React from 'react'
import { useRoutes, Navigate } from 'react-router-dom'

// import Home from '@/pages/home'
// import About from '@/pages/about'
// import UseState from '@/pages/useState'
// import UseEffect from '@/pages/useEffect'

/** 配置路由懒加载 */
const Home = React.lazy(() => import('@/pages/home'))
const About = React.lazy(() => import('@/pages/about'))
const UseState = React.lazy(() => import('@/pages/useState'))
const UseEffect = React.lazy(() => import('@/pages/useEffect'))
const UseRef = React.lazy(() => import('@/pages/useRef'))
const UseLayoutEffect = React.lazy(() => import('@/pages/useLayoutEffect'))
const UseMemo = React.lazy(() => import('@/pages/useMemo'))
const UseCallback = React.lazy(() => import('@/pages/useCallback'))
const Memo = React.lazy(() => import('@/pages/memo'))
const UseReducer = React.lazy(() => import('@/pages/useReducer'))
const UseContext = React.lazy(() => import('@/pages/useContext'))
const WebRTC = React.lazy(() => import('@/pages/webRTC'))

const Router: React.FC = () => {
  const element = useRoutes([
    {
      path: '/',
      element: <Home />
    },
    {
      path: '/about',
      element: <About />
    },
    {
      path: '/use-state',
      element: <UseState />
    },
    {
      path: '/use-effect',
      element: <UseEffect />
    },
    {
      path: '/use-ref',
      element: <UseRef />
    },
    {
      path: '/use-layout-effect',
      element: <UseLayoutEffect />
    },
    {
      path: '/use-memo',
      element: <UseMemo />
    },
    {
      path: '/use-callback',
      element: <UseCallback />
    },
    {
      path: '/memo',
      element: <Memo />
    },
    {
      path: '/use-reducer',
      element: <UseReducer />
    },
    {
      path: '/use-context',
      element: <UseContext />
    },
    {
      path: '/web-rtc',
      element: <WebRTC />
    },

    {
      path: '*',
      element: <Navigate to='/' />
    }
  ])

  return <React.Suspense>{element}</React.Suspense>
}

export default Router
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值