auto watch page's change and generate routes
/** vite.config.js */
import pluginRoutes from 'vite-plugin-generate-routes'
export default defineConfig({
plugins: [
pluginRoutes()
]
...
}
pages:
--| page1.vue
--| page2
----| index.vue
----| page21.vue
----| _id.vue
--| page3
----| page31.vue
----| #componentName.vue
=>
routes:
--| page1
--| page2
--| page2/page21
--| page2/:id
--| page31
- start with '_' means dynamic component:
page/_id.vue
=>/page/:id
- start with '#' means ignore
- Type:
string
- Default:
src/views
- Type:
Function
export default defineConfig({
plugins: [
pluginRoutes({
extend: (route) => {
if(route.path === '/') {
route = {
title: 'root'
meta: {
auth: false
},
...route
}
}
}
})
]
...
}