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

@ctsj/router

v1.0.5

Published

一个基于react-router的可配置路由

Downloads

22

Readme

CTSJ-ROUTER

  一个基于react-router的可配置路由

简介

  写这个东西的目的就是想用react-router2.x方式来配置4.x和5.x的路由,本人认为2.x的配置方式更容易理解,更容易维护,所有的路由节点都在一起,反而从4.x起路由的配置分散在了不同组件的内部,本人觉得这种方式不是很好,这种方式使得路由的配置分散,不易维护。

安装

  npm install @ctsj/router

例子

  1. Router.jsx
import {
  browserConfig,
} from '@ctsj/router';

import Index from './pages/index';
import User from './pages/user';
import UserList from './pages/user/list';
import UserAdd from './pages/user/add';
import UpdateUpdate from './pages/user/update';
import UserInfo from './pages/user/info';
import Setting from './pages/setting';
import Login from './pages/login';

const config = [
  {
    path: '/',
    component: Index,
    routes: [
      {
        path: '/',
        redirect: '/user',
      },
      {
        path: '/setting',
        component: Setting,
      },
      {
        path: '/user',
        component: User,
        routes: [
          {
            path: '/',
            redirect: '/user/list',
          },
          {
            path: '/user/list',
            component: UserList,
          },
          {
            path: '/user/add',
            component: UserAdd,
          },
          {
            path: '/user/update/:id?',
            component: UpdateUpdate,
          },
          {
            path: '/user/info/:id?',
            component: UserInfo,
          },
        ]
      },
    ],
  },
  {
    path: '/login',
    component: Login,
  },
];

const Router = browserConfig(config);

export default Router;
  1. index.jsx
import React from 'react';
import ReactDOM from 'react-dom';

import Router from './router';

ReactDOM.render(
  Router,
  document.getElementById('app'),
);
  1. 嵌套路由(使用props.children进行路由的嵌套,和2.x写法一致)
import React from 'react';

export default props => (
  <div>
    ...
    {props.children}
  <div>
);

API

  • browserConfig(config) - 使用BrowserRouter配置路由
  • hashConfig(config) - 使用HashRouter配置路由
  • memoryConfig(config) - 使用MemoryRouter配置路由

Config

  • path: string - 路径
  • component: ReactElement - 组件
  • redirect: string - 从定向
  • routes: Array - children

引用react-router其他功能

本包导出了react-router-dom的全部组件

其他

demo目录下附带了一个demo