npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-routes-config

v1.0.1

Published

react配置式路由

Readme

react-routes-config

react 配置式路由组件

安装

yarn install react-routes-config

输出文件为UMD,也可以直接用script标签引用,通过window.ReactRoutesConfig访问

使用

如果是CRA创建的模板,可以像如下方式改造App组件

import React, {FC} from 'react';
import {BrowserRouter} from 'react-router-dom';
import Routes from 'react-routes-config';
import routesConfig from './routesConfig'; // 你的路由配置文件,类型为RouteConfig[]

const App: FC = () => {
  return (
    <BrowserRouter>
      <Routes routes={routesConfig}/>
    </BrowserRouter>
  );
};
export interface RouteConfig extends RouteProps {
  path: string; // 匹配路径,以‘/’开头则认为是绝对路径,否则会自动从上层叠加,参考vue-router
  name?: string; // 路由名称
  redirect?: string; // 重定向路径
  meta?: { [key: string]: string }; //路由元信息,可以自定义
  children?: RouteConfig[];
}

配置

// 导出时可不关心路由顺序,匹配时自动按一般路由(Route),重定向(Redirect),global404排序。
export default [
  {
    path: '*',  // 建议最外层设置一个全局404组件
    component: () => '404',
  },
  {
    path: '/dashboard',
    component: ({children}: any) => (<div><p>app</p>{children}</div>),
    children: [
      {
        path: '',
        component: ({children}: any) => (<div><p>home</p>{children}</div>),
        children: [
          {
            path: 'sub-page-1',
            component: () => (<span>sub-page-1</span>),
          },
          {
            path: 'sub-page-2',
            component: () => (<span>sub-page-2</span>),
          },
          {
            path: '/dashboard/outer-link',
            component: () => (<span>outer-link</span>),
          },
        ],
      },
    ],
  },
  {
    path: '/page',
    component: ({children}: any) => (<div><p>page</p>{children}</div>),
    children: [
      {
        path: '/view-one',
        component: () => (<span>view-one</span>),
      },
      {
        path: '/another-redirect',
        redirect: '/home/sub-page-2',
      },
    ],
  },
  {path: '/', redirect: '/dashboard', exact: true},
  {path: '/red', redirect: '/page', exact: true},
] as RouteConfig[]

目录

├── config														
│   ├── webpack.config.js
│   └── webpack.example.config.js			
├── dist									// 输出文件
│   └── index.js
├── example								// 例子
│   ├── App.tsx
│   ├── index.pug
│   ├── index.tsx
│   └── routesConfig.tsx
├── scripts
│   └── release.js
├── src									  // 源码
│   └── Routes.tsx
├── README.md
├── index.d.ts
├── package.json
├── tsconfig.json
└── yarn.lock

本项目受https://www.npmjs.com/package/react-router-config启发