安装
npm install vue-autoroute-webpack-plugin --save-dev
vue.config.js
使用方法在 const InitRouterPlugin = require("vue-autoroute-webpack-plugin");
module.exports = {
configureWebpack: {
plugins: [new InitRouterPlugin()]
}
};
路由特点
- 如果有
@/layouts/index.vue
说明希望有唯一的根容器,则会生成 这种格式
export default [
{
path: "/",
name: "index",
component: () =>
import(/* webpackChunkName: "index" */ "@/layouts/index.vue"),
children:[
// ...
]
}
]
-
如果views下局部文件夹有
layout.vue
,则生成嵌套路由 -
如果views下局部文件夹没有
layout.vue
,则拍平路由 目前多层嵌套,拍平有问题,先支持一层嵌套 -
约定式路由约定
- 动态参数路由 - _id.vue 代表 /:id
- 不生成到路由表 - -id.vue 则不在routes数组
- 支持在vue文件中的data设置redirect和meta对象