Skip to content

Commit

Permalink
feat: support vue-router 4 in generated template
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsn committed Jan 6, 2021
1 parent 699834e commit 9f9eac4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/generator/template
/generator/template-vue3
node_modules
11 changes: 9 additions & 2 deletions generator/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module.exports = (api) => {
/* eslint-disable-next-line no-unused-vars */
module.exports = (api, _options = {}, rootOptions = {}) => {
const isVue3 = rootOptions.vueVersion === '3'

api.extendPackage({
dependencies: {
'vue-router-layout': '^0.2.0',
'vue-router-layout': isVue3 ? '^0.2.0' : '^0.1.2',
},
devDependencies: {
'vue-auto-routing': '^1.0.0',
Expand All @@ -17,6 +20,10 @@ module.exports = (api) => {

api.render('./template')

if (isVue3) {
api.render('./template-vue3')
}

if (api.invoking) {
api.postProcessFiles((files) => {
Object.keys(files).forEach((name) => {
Expand Down
20 changes: 20 additions & 0 deletions generator/template-vue3/src/router/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createRouter, createWebHistory } from 'vue-router'
import routes from 'vue-auto-routing'
import { createRouterLayout } from 'vue-router-layout'

const RouterLayout = createRouterLayout(layout => {
return import('@/layouts/' + layout + '.vue')
})

const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes: [
{
path: '/',
component: RouterLayout,
children: routes
}
]
})

export default router
2 changes: 1 addition & 1 deletion generator/template/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const RouterLayout = createRouterLayout(layout => {
})

export default new Router({
mode: "history",
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
Expand Down

0 comments on commit 9f9eac4

Please sign in to comment.