Skip to content

Commit 9f9eac4

Browse files
committed
feat: support vue-router 4 in generated template
1 parent 699834e commit 9f9eac4

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/generator/template
2+
/generator/template-vue3
23
node_modules

generator/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
module.exports = (api) => {
1+
/* eslint-disable-next-line no-unused-vars */
2+
module.exports = (api, _options = {}, rootOptions = {}) => {
3+
const isVue3 = rootOptions.vueVersion === '3'
4+
25
api.extendPackage({
36
dependencies: {
4-
'vue-router-layout': '^0.2.0',
7+
'vue-router-layout': isVue3 ? '^0.2.0' : '^0.1.2',
58
},
69
devDependencies: {
710
'vue-auto-routing': '^1.0.0',
@@ -17,6 +20,10 @@ module.exports = (api) => {
1720

1821
api.render('./template')
1922

23+
if (isVue3) {
24+
api.render('./template-vue3')
25+
}
26+
2027
if (api.invoking) {
2128
api.postProcessFiles((files) => {
2229
Object.keys(files).forEach((name) => {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { createRouter, createWebHistory } from 'vue-router'
2+
import routes from 'vue-auto-routing'
3+
import { createRouterLayout } from 'vue-router-layout'
4+
5+
const RouterLayout = createRouterLayout(layout => {
6+
return import('@/layouts/' + layout + '.vue')
7+
})
8+
9+
const router = createRouter({
10+
history: createWebHistory(process.env.BASE_URL),
11+
routes: [
12+
{
13+
path: '/',
14+
component: RouterLayout,
15+
children: routes
16+
}
17+
]
18+
})
19+
20+
export default router

generator/template/src/router/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const RouterLayout = createRouterLayout(layout => {
1010
})
1111

1212
export default new Router({
13-
mode: "history",
13+
mode: 'history',
1414
base: process.env.BASE_URL,
1515
routes: [
1616
{

0 commit comments

Comments
 (0)