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 🙏

© 2024 – Pkg Stats / Ryan Hefner

unplugin-router

v0.0.7

Published

The protocol routing scheme applicable to 'vue' and 'react'

Downloads

2

Readme

unplugin-router

unplugin-router是以项目文件或目录进行分析后自动生成路由配置的约定式路由方案,支持热更新,支持在vite和webpack中使用

迭代计划

  • 支持vite和webpack(v1.x 已支持)
  • 支持生成vue-router3.x和vue-router4.x(v1.x 已支持)
  • 支持生成react-router5.x、react-router6.x (v2.x 暂未支持)

vue | react

特点功能

  • 支持动态路由
  • 支持嵌套路由
  • 支持404路由
  • 支持权限路由
  • 支持prompt路由

安装与插件注入

// 使用npm或yarn进行安装
npm i unplugin-router --save-dev
// 在vite中使用
import unrouter from 'unplugin-router/vite'
export default defineConfig({
  ...,
  plugins: [
    unrouter(options)
  ],
})
//在webpack中使用
module.exports = {
  plugins:[
    require('unplugin-router/webpack').default(options)
  ]
}

ts类型支持

在typescript项目中,可以通过引入client.ts文件对route、register进行类型扩展
在目录下新建.d.ts文件

/// <reference types="unplugin-router/client" />

参数配置(options)

| 属性名 | 说明 | 类型 | 可选值 | 默认值 | | --- | --- | --- | --- | --- | | platform | 指定生成的路由类型 | string | vue/react | vue | | mode | 指定要使用的路由模式 | string | hash/history | hash | | jumpTo | 当修改路由文件后是否自动跳转到该路由页面 | boolean | - | true | | entry | 指定unplugin-router的扫描入口 | string | - | src/pages | | exclude | 指定哪些文件或目录下的文件不应该被作为路由生成 | {dir:string[];file:string[]} | - | 见下 | | noAuthRedirect | 指定无页面权限时导航的路由 | string | - | / | | notInAuthsBehaviour | 指定无权限时的处理方式,默认视为有权限 | boolean | - | true | | name | 指定路由名称的生成规则 | NameConfig | - | 默认取path值并合并为首字母大写的驼峰式 | | path | 设置path的生成规则 | PathConfig | - | 默认path.prefix为false | | print | 是否输出路径到name、path的映射,建议非ts项目启用 | boolean | - | false | | console | 是否打印日志信息,默认开发环境打印 | boolean | - | true |

默认被跳过的文件

  • 以 . 或 _ 开头的文件或目录
  • component 、 components 、 utils 、 util 、 helper 、 helpers目录
  • 非.vue文件(vue)
  • 非.tsx或.jsx(react)

NameConfig

interface NameConfig{
  /**
   * 默认为true
   * 表示仅在开发环境下生成name属性
   * 页面内注解的name不受此配置影响
   */
  onlyDev?:boolean;
  /**
   * 默认为false
   * 设置true后,当出现重复的路由名称时,会以当前路由name+'_'+数值进行替换
   */
  repair?:boolean;
  // 在路由名称生成后被回调,可return一个自定义的name值进行替换
  created?:(route:RouteItem)=>string;
}

PathConfig

interface PathConfig{
  /**
   * 指定根路由(如index),匹配到时,path会被设置为''
   * 仅作用于子路由
   * 默认子路由与父路由名称一致时,设置path为''
   */
  rootNamed?:string;
}

代码示例

examples目录