react 路由懒加载引起的问题

Error handled by React Router default ErrorBoundary: Error: A component suspended while responding to synchronous input. This will cause the UI to be replaced with a loading indicator. To fix, updates that suspend should be wrapped with startTransition.

问题是在路由页面使用了react的懒加载,路由切换的时候异步加载的问题报错
 

// router.js
import React,{lazy} from 'react'

// import Home from "../pages/home";
// import Login from "../pages/login";
// import NotFound from "../pages/notFound";

const  Home  = lazy(()=>import("@/pages/home"));

const  Login  = lazy(()=>import("@/pages/login"));
const  NotFound  = lazy(()=>import("@/pages/notFound"));

只需要在路由的外层包一层Suspense标签,即可异步等待加载路由

import { Suspense } from 'react';
ReactDOM.createRoot(document.getElementById('root')!).render(
  <Suspense>
    <RouterProvider
      router={router}>
    </RouterProvider>
  </Suspense>
)

相关推荐

  1. vue

    2024-04-02 11:38:03       44 阅读
  2. 2024-04-02 11:38:03       33 阅读
  3. React和Vue实现

    2024-04-02 11:38:03       60 阅读
  4. React和Vue实现

    2024-04-02 11:38:03       52 阅读
  5. React和Vue实现

    2024-04-02 11:38:03       52 阅读
  6. 关于实现

    2024-04-02 11:38:03       33 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-02 11:38:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-02 11:38:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-02 11:38:03       82 阅读
  4. Python语言-面向对象

    2024-04-02 11:38:03       91 阅读

热门阅读

  1. 计算机断层扫描采集软件

    2024-04-02 11:38:03       39 阅读
  2. vector容器(二)

    2024-04-02 11:38:03       39 阅读
  3. QT(6.5) cmake构建C++编程,多线程

    2024-04-02 11:38:03       36 阅读
  4. C++ hex转uint,uint 互相转换,uint转byte

    2024-04-02 11:38:03       41 阅读
  5. sql注入详解

    2024-04-02 11:38:03       36 阅读
  6. Qt QML 坐标转换函数

    2024-04-02 11:38:03       39 阅读
  7. Python 约瑟夫环问题

    2024-04-02 11:38:03       34 阅读
  8. rust实现UDP服务器

    2024-04-02 11:38:03       41 阅读