Skip to content

Commit

Permalink
Merge pull request #52 from ojvribeiro/feat-dynamic-route
Browse files Browse the repository at this point in the history
feat(core): dynamic routes
  • Loading branch information
ojvribeiro authored Oct 1, 2022
2 parents 016bd09 + 5d83b1a commit f98d8f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .vulmix/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,31 @@ pageComponents
})
})

/**
* Dynamic Pages
*/
const dynamicPageComponents = require.context('@pages/', true, /\[(.*)\]\.(vue|js)$/i)
dynamicPageComponents
.keys()
.map(key => {
let slugName = key
.split('.')[1]
.replace(/([A-Z])/g, '-$1')
.replace(/(^-)/g, '')
.toLowerCase()

if (slugName.match(/\/index$/)) {
slugName = slugName.replace('/index', '/')
} else {
slugName = slugName.replace(/\/\[(.*)\]/, '/:$1')
}

routes.push({
path: slugName === '/index' ? '/' : `/${slugName}`,
component: dynamicPageComponents(key).default,
})
})

routes.push({
path: '/:pathMatch(.*)*',
component: require('@/pages/404.vue').default,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"@vue/compiler-sfc": "^3.2.37",
"@vueuse/core": "^9.2.0",
"@vueuse/head": "^0.7.12",
"@vueuse/router": "^9.3.0",
"autoprefixer": "^10.4.8",
"browser-sync": "^2.27.10",
"browser-sync-webpack-plugin": "^2.3.0",
"imagemin-jpegtran": "^7.0.0",
"laravel-mix": "^6.0.49",
"laravel-mix-ejs": "^2.0.0",
"laravel-mix-replace-in-file": "^0.1.0",
Expand Down

1 comment on commit f98d8f8

@vercel
Copy link

@vercel vercel bot commented on f98d8f8 Oct 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vulmix – ./

vulmix-ojvribeiro.vercel.app
vulmix.vercel.app
vulmix-git-main-ojvribeiro.vercel.app

Please sign in to comment.