Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

🌠 A React Component for quick configuring route

License

NotificationsYou must be signed in to change notification settings

Bert0324/react-routers

Repository files navigation

fre logo

React Routers

🌠 A React Component for quick configuring route

LICENCENPM VERSIONPR WELCOMESTARFOLK

⭐ Features

  • Static Routes likereact-router-config
  • Route Guard andkeep-alive likeVue
  • Auto Lazy Load
  • Easyprefetch
  • Simple Transition Animation
  • Changedocument.title with Configuration
  • Tiny Size, unpacked 13KB
  • Full Typescript Support

🏠 Installation

  • yarn add react-routers

🎠 Example & Playground

import{BrowserRouter}from'react-router-dom';import{Routers}from'react-routers';constApp=()=>{return(<BrowserRouterbasename='prefix'><Routersrouters={[{path:'/page',Component:async()=>(awaitimport('./Component')).Component}]}/></BrowserRouter>)}

A playground ofreact-routers inHERE.

📑 API

Props ofRouters

routers

The Router configuration, the path in children will be jointed with the path in parent. Its type is as below:

interfaceIPageRouter{/**     * route path     */path:string;/**     * document.title, if not set, will use original title in html     */name?:string;/**     * the lazy load Component     */Component?:()=>(Promise<ComponentType<any>>|ComponentType<any>);/**     * children configuration     * - child node will inherit parent node configuration     * - child node configuration has higher priority than parent node configuration     */children?:IPageRouter[];/**     * triggered before entering route     * - if return false, deny to enter route\     * - after `beforeEach`     */beforeRoute?:IBeforeRoute;/**     * triggered after entering route     * - if return false, deny to enter route     * - ahead of `afterEach`     */afterRoute?:IAfterRoute;/**     * maintains component state and avoids repeated re-rendering for the route     * - default is `false`     * - its priority is higher than `keepAlive` in props     */keepAlive?:boolean;/**     * transition animation     */transition?:ITransition;/**     * the path list to prefetch     * - parent node prefetch will be append after current node prefetch     */prefetch?:string[];}

fallback

A fallback react tree to show when a Suspense child (like React.lazy) suspends, and before entering the route. It must be a React Component.

redirect

redirect path.

beforeEach

triggered before entering route

  • if return false, deny to enter route
  • ahead of anybeforeRoute

afterEach

triggered after entering route

  • if return false, deny to enter route
  • after anyafterRoute

keepAlive

do maintains component state and avoids repeated re-rendering for each route

  • default isfalse

switchRoute

Do select only one route like<Switch>

  • default istrue

transition

transition animation. Its type is as below:

typeITransition={/**     * the css style after matched     */match:CSSProperties;/**     * the css style after unmatched     */notMatch:CSSProperties;/**     * the css style of transition     */trans:CSSProperties;/**     * keep component after unmatched     * - default is `500`ms     */delay?:number;};

or directly use embedded animation objects.

delay

loading delay

  • default is100ms

prefetchDelay

how much time delayed to start prefetch after main thread is idle

  • default is0 ms

Hooks

useActive &useDeactive

The hook triggered when the component's active state has changed.

WHEN DO YOU NEED IT?

  • If a component is set askeepAlive, and you want to trigger something when the component is activated.
import{useActive,useDeactive}from'react-routers';useActive(()=>{/* Called when the component is activated. */});useDeactive(()=>{/* Called when the component is deactivated. */});

useParams &useRouteMatch

A wrapped function ofuseParams &useRouteMatch

Asreact-router don't have the configuration configured inreact-routers, if you want to get params in route, you should use this hook.

import{useParams,useRouteMatch}from'react-routers';// /blog/:slugconst{ slug}=useParams<{slug?:string}>();constmatch=useRouteMatch<{slug?:string}>();

Embedded Animation

The object which can be put intransition, includesFade,LeftFade,RightFade,TopFade,BottomFade,LeftSlide,RightSlide,TopSlide,BottomSlide.

💻 Development

  • yarn
  • preview=true yarn dev
  • yarn build

🍧 License

React Routers isMIT licensed.


[8]ページ先頭

©2009-2025 Movatter.jp