Giter Site home page Giter Site logo

Comments (1)

fz6m avatar fz6m commented on May 21, 2024

现在 src/loading.tsx 可以统一定义全局所有页面级别在懒加载时的 loading 动画,如果你需要每个页面不同的话,在这里面判断一下吧。

比如:

// .umirc.ts

  routes: [
    { path: '/docs', component: 'docs', loading: 'A' },
  ]
// src/loading.tsx

import { ReactNode } from 'react'
import { useRouteProps } from 'umi'

const map: Record<string, ReactNode> = {
  A: <div>A loading</div>, // or import a component, don't use async import
}

export default function Loading() {
  const props = useRouteProps()

  const fallback = (
    <div>fallback loading</div>
  )

  if (props?.loading) {
    return map[props.loading] || fallback
  }

  return fallback
}

你提到的在每个页面下新增 loading.tsx 文件来预加载,现在约定式路由里每个文件都会被视为一个路由路径,添加 loading.tsx 就变成 /loading 的路由了,所以这种方式是做不到的,比如 nextjs 也只能在 app dir 而不是 pages dir 去新增各种约定文件的设定。

另外现在绝大多数用户使用的是配置式路由,自己根据配置调整下或者根据 location.path 判断下条件渲染吧。

from umi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.