1. @vusion/routes-loader
Vusion Routes Loader
@vusion/routes-loader
Package: @vusion/routes-loader
Created by: vusion
Last modified: Thu, 26 Oct 2023 03:26:46 GMT
Version: 0.4.0
License: MIT
Downloads: 490
Repository: https://github.com/vusion/packages

Install

npm install @vusion/routes-loader
yarn add @vusion/routes-loader

@vusion/routes-loader

约定式路由

嵌套为主的路由结构。

规则

  • 目录结构决定路由层级
  • 如果模块或枝页面下面没有index.vue,会用LWrapper组件填充
  • 以下目录为关键词目录,内部不应该有与路由相关的视图,文件和子文件路径都不会添加为路由:assetscomponents, directives, filters, mixins, utils, styles, service, module
  • 以下目录为占位符目录,只是为了方便归类视图文件,占位目录名不体现在路径上:viewslayout
  • _id会替换为变量类型:id
  • _id_会替换为可选变量类型:id?
  • any+会替换为通配类型any*
  • =outside会将该文件及子文件的路径做为固定路由,拉出嵌套结构

可以参考 normalize 函数。

示例

├─ account/                 #
│   ├─ module/              # 忽略关键字目录
│   ├─ components/          # 忽略关键字目录
│   │   ├─ s-detail.vue     #
│   │   │   │   └─ ...
│   ├─ utils/               # 忽略关键字目录
│   ├─ views/
│   │   ├─ list.vue         #
│   │   ├─ settings/        #
│   │   │   ├─ _id_.vue     #
│   │   ├─ micro/           #
│   │   │   ├─ cloud++.vue  #
│   │   ├─ detail/          #
│   │   │   ├─ index.vue    #
│   │   │   ├─ info.vue     #
│   │   │   ├─ monitor.vue  #
│   │   │   ├─ =deep/       #
│   │   │   │   ├─ list.vue #
│   │   └─ ...

将会生成

 export default {
    path: 'account',
    component: LWrapper,
    children: [
        { path: '', redirect: 'list' },
        { path: 'list', component: () => import(/* webpackChunkName: 'account' */ './views/list.vue') },
        { path: 'settings', component: LWrapper, children: [
            { path: ':id?', component: () => import(/* webpackChunkName: 'account' */ './views/detail/_id_.vue') },
        ] },
        { path: 'micro', component: LWrapper, children: [
            { path: '', redirect: 'cloud**' },
            { path: 'cloud**', component: () => import(/* webpackChunkName: 'account' */ './views/micro/cloud++.vue') },
        ] },
        { path: 'detail', component: () => import(/* webpackChunkName: 'account' */ './views/index.vue'), children: [
            { path: '', redirect: 'info' },
            { path: 'info', component: () => import(/* webpackChunkName: 'account' */ './views/detail/info.vue') },
            { path: 'monitor', component: () => import(/* webpackChunkName: 'account' */ './views/detail/monitor.vue') },
        ] },
        { path: 'detail/deep/list', component: () => import(/* webpackChunkName: 'account' */ './views/detail/deep/list.vue') },
    ],
};

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin