You can pass the routes to plugins (like layout generators) to modify them. However, note that manual manipulations of the routes object will not be reflected in the generated types.
If you need type safety for your modified routes, use build-time routes instead.
Example of using setupLayouts with generated routes:
import { ViteSSG } from 'vite-ssg'
import { setupLayouts } from 'virtual:generated-layouts'
import App from './App.vue'
import { routes } from 'vue-router/auto-routes'
export const createApp = ViteSSG(
App,
{
routes: setupLayouts(routes),
base: import.meta.env.BASE_URL,
},
(ctx) => { /* ... */ }
)
import { ViteSSG } from 'vite-ssg'
import { setupLayouts } from 'virtual:generated-layouts'
import App from './App.vue'
import generatedRoutes from '~pages' // [!code --]
import { routes } from 'vue-router/auto-routes' // [!code ++]
const routes = setupLayouts(generatedRoutes) // [!code --]
// https://github.com/antfu/vite-ssg
export const createApp = ViteSSG(
App,
{
routes, // [!code --]
routes: setupLayouts(routes), // [!code ++]
base: import.meta.env.BASE_URL,
},
(ctx) => {
// install all modules under `modules/`
Object.values(
import.meta.glob<{ install: UserModule }>('./modules/*.ts', {
eager: true,
})
).forEach((i) => i.install?.(ctx))
}
)