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

@jl-org/vite-auto-route

v1.0.53

Published

自动生成路由配置,支持嵌套路由

Downloads

1

Readme

自动生成路由配置,支持嵌套路由

安装

npm i @jl-org/vite-auto-route

使用

如果遇到数组没有匹配到路由,请先删除 /node_modules/.vite 文件夹,再重新编译

import { genRoutes } from '@jl-org/vite-auto-route'
import { createRouter, createWebHistory } from 'vue-router'


const routes = genRoute()
/** 未匹配路径处理 */
routes.push({
    path: '/:pathMatch(.*)*',
    redirect: '/YourPath',
} as any)

const router = createRouter({
    history: createWebHistory(),
    routes
})

export default router

如果你用的不是 vite,并且支持 node 环境,请使用https://www.npmjs.com/package/@jl-org/auto-route

他能做什么?

自动生成路由配置,支持:

  1. 嵌套路由
  2. 路由守卫
  3. 路由参数
  4. 路由重定向
  5. meta

规范

如上图示例,因为 vite 的工具,无法使用变量来查找目录

所以你的路由需按照配置写,不能自定义配置

/src/views/下建立你的路由文件吧

/src/views/index.vue,会作为路由的首页,且必须存在

/src/views/about/index.vue,会作为首页的子路由

meta 为可选项

我不想让 src/views/index.vue 作为首页怎么办?

当你可能需要 /home 作为首页,那么你可以进行如下配置

首先,src/views/index.vue 必须创建,你里面可以不写东西,比如

<template></template>

创建 src/views/meta.{j,t}s 文件,里面写上重定向即可
然后你就可以在 src/views/home/index.vue 编写你的首页了

export default {
    redirect: '/home',
}

如何传递 meta

在同级目录下,创建一个 meta.ts | meta.js 文件

并默认导出一个对象,该对象包含了所有需要传递的 meta 信息。

如何使用嵌套路由 ?

在一个目录下,创建一个新的文件夹,里面包含 index.vue 文件即可

如果使用路由守卫?

meta.ts | meta.js 文件中,添加一个 beforeEnter 函数即可

beforeEnter 会被自动提取出来

如果使用 redirect

meta.ts | meta.js 文件中,添加一个 redirect 对象即可

redirect 会被自动提取出来

如何使用 param

路由参数,$ 代表可选参数

  • about/[param]
  • about/[param$]