All Projects → ktsn → Vue Cli Plugin Auto Routing

ktsn / Vue Cli Plugin Auto Routing

Licence: mit
Automatically resolve pages and layouts routing

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Cli Plugin Auto Routing

Vue Blog
🎉 基于vue全家桶 + element-ui 构建的一个后台管理集成解决方案
Stars: ✭ 208 (-11.11%)
Mutual labels:  vue-router
Vuex Router Sync
Effortlessly keep vue-router and vuex store in sync.
Stars: ✭ 2,499 (+967.95%)
Mutual labels:  vue-router
Clout
HTTP route-matching library for Clojure
Stars: ✭ 228 (-2.56%)
Mutual labels:  routing
Vue Fallowfish
🐠vue全家桶仿闲鱼部分布局以及功能实现
Stars: ✭ 211 (-9.83%)
Mutual labels:  vue-router
Falco
A functional-first toolkit for building brilliant ASP.NET Core applications using F#.
Stars: ✭ 214 (-8.55%)
Mutual labels:  routing
Silk
Routing for Clojure & ClojureScript
Stars: ✭ 217 (-7.26%)
Mutual labels:  routing
Vue Admin Template
a vue2.0 minimal admin template
Stars: ✭ 15,411 (+6485.9%)
Mutual labels:  vue-router
The Elmish Book
A practical guide to building modern and reliable web applications in F# from first principles
Stars: ✭ 231 (-1.28%)
Mutual labels:  routing
Vue Wp Starter
A WordPress Vue.js starter plugin
Stars: ✭ 214 (-8.55%)
Mutual labels:  vue-router
Vuemmerce
👉 Responsive ecommerce template 🛒 built with Vue.js and Nuxt.js
Stars: ✭ 223 (-4.7%)
Mutual labels:  vue-router
Aqueduct
Dart HTTP server framework for building REST APIs. Includes PostgreSQL ORM and OAuth2 provider.
Stars: ✭ 2,412 (+930.77%)
Mutual labels:  routing
Yoyocms.abpprojecttemplate
一个基于-vue+vuex+vue-router+EF开发的权限管理系统
Stars: ✭ 213 (-8.97%)
Mutual labels:  vue-router
Web designer
网页设计器图形化工具,通过拖拽组件进行页面排版和生成页面代码
Stars: ✭ 219 (-6.41%)
Mutual labels:  vue-router
Venture Management
一个包含vuejs和nodejs技术的全栈项目
Stars: ✭ 208 (-11.11%)
Mutual labels:  vue-router
Mmf Blog Vue2
mmf-blog vue2.0 (vue2, vue-router, vuex)
Stars: ✭ 232 (-0.85%)
Mutual labels:  vue-router
Ui Router
The de-facto solution to flexible routing with nested views in AngularJS
Stars: ✭ 13,738 (+5770.94%)
Mutual labels:  routing
Filmsys
一个使用Vue全家桶和后台Express框架结合Mysql数据库搭建起来的移动端电影售票和管理系统,实现了热映、即将上映、电影和影院全局搜索、评论、选座、购票、点赞、收藏、订单等一系列购票和管理流程功能
Stars: ✭ 217 (-7.26%)
Mutual labels:  vue-router
Looking Glass
Easy to deploy Looking Glass
Stars: ✭ 233 (-0.43%)
Mutual labels:  routing
React Firebase Admin
React ⚛️ starter kit with Firebase 🔥 and Bulma for setting up an admin dashboard - Highly scalable, PWA, Serverless
Stars: ✭ 232 (-0.85%)
Mutual labels:  routing
Vite Vue3 Tailwind Starter
Vite 2.x + Vue 3.x + Tailwind 2.x (starter) ⚡
Stars: ✭ 205 (-12.39%)
Mutual labels:  vue-router

vue-cli-plugin-auto-routing

vue-cli-plugin-auto-routing Dev Token

Vue CLI plugin that provides auto routing feature.

Overview

Ensure you are in a project generated by Vue CLI >= v3. You install this plugin by running the following command:

# If you did not install router plugin yet
$ vue add router

# Install vue-cli-plugin-auto-routing
$ vue add auto-routing

After adding the plugin, the file structure will be the below.

src/
├── pages/
├── layouts/
└── router/

Pages

.vue files under the pages/ directory will be automatically resolved to generate routing. Vue Router routes options will be configured with the file structure under the pages/. The generated routing is same with Nuxt's routing.

Note that directories and files started and ended with __ (two underscores, e.g. __foo__.vue) will be ignored.

For example, when you have the following page components:

pages/
├── __partial__.vue
├── index.vue
├── users.vue
└── users/
    └── _id.vue

It is resolved to the below routes. Note that _ prefixed components generate dynamic routing.

export default [
  {
    name: 'index',
    path: '/',
    component: () => import('@/pages/index.vue')
  },
  {
    name: 'users',
    path: '/users',
    component: () => import('@/pages/users.vue'),
    children: [
      {
        name: 'users-id',
        path: ':id?',
        component: () => import('@/pages/users/_id.vue')
      }
    ]
  }
]

If you want to make route param required, create a directory for the param and add index.vue in the directory. In the above example, if you replace users/_id.vue with users/_id/index.vue, :id param will be required.

<route> custom block

If a page component has <route> custom block, the content json will be merged with route config.

For example, if index.vue has the following <route> block:

<route>
{
  "name": "home",
  "meta": {
    "requiresAuth": true
  }
}
</route>

<template>
  <h1>Hello</h1>
</template>

The generated route config is like the following:

module.exports = [
  {
    name: 'home',
    path: '/',
    component: () => import('@/pages/index.vue'),
    meta: {
      requiresAuth: true
    }
  }
]

Layouts

Components under the layouts/ directory will be used as shared layout component in the application. You can choose a layout by specifying layout component option in a page component. The default value of layout is 'default'. That means when you omit layout options, layouts/default.vue will be choosed as the layout component. This is the same concept with Nuxt's layouts.

For example, when you have layouts/foo.vue and pages/index.vue:

<!-- layouts/foo.vue -->
<template>
  <div>
    <h1>Foo Layout</h1>
    <router-view />
  </div>
</template>
<!-- pages/index.vue -->
<template>
  <p>index.vue</p>
</template>

<script>
export default {
  // You can specify layout component name here (default value is 'default')
  layout: 'foo'
}
</script>

The following html will be rendered:

<div>
  <h1>Foo Layout</h1>
  <p>index.vue</p>
</div>

Modifying Chunk Name

A chunk name from auto generated file can be conflicted with your code. You may see the below error log in that case:

 ERROR  Failed to compile with 1 errors
 error  in ./node_modules/vue-auto-routing/index.js
It's not allowed to load an initial chunk on demand. The chunk name "index" is already used by an entrypoint.
 ERROR  Build failed with errors.
error Command failed with exit code 1.

To avoid this error, you can set chunkNamePrefix option to change the auto generated chunk name.

// vue.config.js

module.exports = {
  pluginOptions: {
    autoRouting: {
      // Specify a prefix which will be added to all auto generated chunk name.
      chunkNamePrefix: 'page-'
    }
  }
}

Options

You can specify options for this plugin under pluginOptions.autoRouting in vue.config.js. The options are simply passed to vue-auto-routing options. You can see the available options list here.

// vue.config.js

module.exports = {
  pluginOptions: {
    autoRouting: {
      // Optionally specify a custom output file, relative to the project root
      outFile: "src/router/routes.js",
      // Specify other vue-auto-routing options here
      nested: false
    }
  }
}

Related Projects

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].