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

@exvu/umi-plugin-dynamic-route

v0.0.12

Published

动态路由

Readme

@exvu/umi-plugin-dynamic-route

实现umi2,umi3动态路由。

实现原理

通过修改routes对象,再触发render使界面刷新,让新路由生效。

安装

# or yarn
$ npm install @exvu/umi-plugin-dynamic-route --save-dev
$ yarn add @exvu/umi-plugin-dynamic-route -D

Usage

需要两个步骤开始.

1. 配置 .umirc.ts

export default defineConfig({
  dynamicRoutes: {
    routeKey:"routeKey1",//指定路由查询的搜索键
    routes:{}//各个模块的动态路由
  },
  routes: [
    {
      path: '/',
      //umi2 umi3 配置雷同
      wrappers: [
        '@/wrappers/auth'
      ],
      component: '@/layouts/BlankLayout',
      routeKey1:"home",
      routes: [
      ]
    }
  ],
});

12. 配置 app.ts

import { getDynamicRoutes, findRouteByKey } from 'umi';

export function patchDynamicRoutes({  routes, test,...options }) {
    //test 通过reloadRoutes传递的自定义参数
    
    console.log("执行patchDynamicRoutes");
    //根据key快速定位到指定节点。
    const targetRoute = findRouteByKey(routes, 'home', 'routeKey1');
    if (targetRoute) {
        //获取某个模块的路由
        const dynamicRoutes = getDynamicRoutes('test')
        if (targetRoute.route && dynamicRoutes) {
            //更新路由逻辑
            targetRoute.route.routes.splice(targetRoute.route.routes.length - 1, 0, ...dynamicRoutes)
            console.error("替换路由成功", routes)
        } else {
            console.error("未找到动态路由", dynamicRoutes)
        }

    } else {
        console.error("未找到目标路由")
    }
}

3. 在项目中使用

请求更新路由(项目任意位置调用) 可以在reloadRoutes将自定义参数传递给app.ts的patchDynamicRoutes

import { patchRoutes,reloadRoutes,dynamic } from 'umi';
//更新路由
reloadRoutes({
  test:'自定义字段'
});

配置文档

|属性|默认值|描述| |:-:|:-:|:--------:| |routeKey|routeKey|指定路由查询的搜索键 |routes|{}|各个模块的动态路由

|函数|描述| |:-:|:-:|:--------:| |reloadRoutes(option?:Option[])|请求重新路由,在更新路由之前会触发patchDynamicRoutes修改路由| |getRoutes|获取umi的路由配置| |getDynamicRoutes(key?:string)|获取动态路由,若传递key就获取指定模块的动态路由,否则获取全部的动态路由配置| |findRouteByKey(routes: Route[],key: string,routeKey:string)|根据键查询路由|

|函数|描述| |:-:|:-:|:--------:| |patchDynamicRoutes(option?:Option[])|修改动态配置路由

umi2完整例子请看 in ./example-umi2 umi3完整例子请看 in ./example-umi3

LICENSE

MIT