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

auto-router-vue3

v1.3.13

Published

生成router, 基于vue

Downloads

63

Readme

一个基于Vue的自动路由解析工具

将文件转地址转换为路由地址

本来是基于vue3的,所以名字带了vue3,后来兼容了vue2

安装

npm install -g auto-router-vue3
# or 
npm install -d auto-router-vue3

使用方式

两种使用方式:

  1. 命令行执行
  2. 引入插件执行

命令行执行方式

可以使用命令 auto-router -h

Options:
  -sc,--set-config <config>  设置配置(json字符串)
  -v,--version               获取版本号
  -h, --help                 display help for command

Commands:
  set [options]              配置信息
  get-config                 获取配置信息
  render                     手动编译所有路由
  watch                      路由监听
  • set命令: auto-router set -h 查看帮助文档
配置信息

Options:
-ed,--excludeDir <excludeDir>    设置排除目录 , 以;隔开
-er,--excludeReg <excludeReg>    设置排除目录,正则字符串(有则优先)
-ep,--excludePath <excludePath>  设置排除路径, 以;隔开
-p,--pagePath <pagePath>         设置页面目录
-t,--type <type>                 设置渲染类型(simple,complex)
-h, --help                       display help for command
  • render 命令: auto-router render 编译所有路由
  • watch 命令: auto-router watch 监听路由变化

配置说明

|字段| 默认 | 数据结构 | 说明 | 示例 | |:---|:-------------|:-------------|:------------------------------------|:----------------------------------------| |excludeDir| null | Array , null | 若不配置则,则为null; 排除配置中的路由地址, 优先级高 | ["src/views/Layout", "src/views/Login"] | |excludeReg| null | String , null | 排除匹配的路由地址, 优先级中 | "component(s)?" | |excludePath| null | Array , null | 排除匹配的路径名 , 给不熟悉正则的人使用的 优先级低 | ["component", "components"] | |pagePath| null | String | 页面所在的根目录 | "pages" | |type| simple, complex | String | 页面的渲染类型, simple: 单级路由, complex:多级路由 | "simple" | |defaultRedirect| list| String | 正则匹配文件名 , 设置默认重定向地址| "^list$" |

在vite 中使用vitePluginVueAutoRouter插件

使用该插件 , 可以在开发过程中实时渲染.

// 引入
import vitePluginVueAutoRouter from "auto-router-vue3";
// 使用方式
export default ({mode})=>{
  return defineConfig({
    plugins: [vue(),
      // 插件可以传递配置参数
      vitePluginVueAutoRouter()]
  })
}

在vue-cli中使用插件(webpack)

由于vue-cli使用的webpack, 所以需要在vue.config.js中配置插件

// 引入webpack插件
const WebpackPluginAutoRouter =  require("auto-router-vue3/cjs").WebpackPluginAutoRouter;
// 在下面的configureWebpack.plugins中添加
module.exports = {
  configureWebpack: {
    plugins: [
      new WebpackPluginAutoRouter({
        excludePath:["src/views/Layout"], // 排除路径
        excludeReg:"((component(s)?)|(utils)|(route(r)?))", // 排除路径正则匹配
        pagePath:"views", // 页面目录
        type:"complex" // 渲染类型 , simple: 简单模式, 不包含多级路由, complex: 复杂模式 , 可以有多级路由,按目录分级
      })
    ],
  },
}

路由配置

  • 在.vue文件中 , export中, 添加
  _config:{ 
    route:{ // 和配置route一样, 不要配置component字段
      name:"路由name", // 路由中 ,如果有该name字段,则使用name来命名路由, 如果没有则使用文件名命名
      meta:{},
      path:"", // 如果存在这个字段 , 则优先使用path作为路由 
      ...
    }
  }

例如:

    exports default{
        _config:{
            route:{ // 和配置route一样, 不要配置component字段
                name:"路由name", // 路由中 ,如果有该name字段,则使用name来命名路由, 如果没有则使用文件名命名
                meta:{},
                path:"", // 如果存在这个字段 , 则优先使用path作为路由 
                ...
            }
        },
        data(){
           return {
           
             }   
        }
    }
  • 如果使用的setup 则定义一个_config变量来实现
    const _config= {
      route:{ // 和配置route一样, 不要配置component字段
              name:"路由name", // 路由中 ,如果有该name字段,则使用name来命名路由, 如果没有则使用文件名命名
              meta:{},
              path:"", // 如果存在这个字段 , 则优先使用path作为路由 
              ...
          }
    }

由于导入的方式是用@方式导入 , 所以还要在vite.config中添加以下配置:

  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  }