#pages:extend with nested routes (link to repo)

2 messages · Page 1 of 1 (latest)

hasty cradle
tough spade
#

@hasty cradle Here's an implementation that works for me via a custom Nuxt Module.

import { defineNuxtModule } from '@nuxt/kit'
import path from 'node:path'
import { glob } from 'glob'

export default defineNuxtModule({
  hooks: {
    async 'pages:extend'(pages) {
      const routesFilesPaths = await glob('./src/views/**/*.routes.ts')
      const routes = await Promise.all(
        routesFilesPaths.map(routesFilePath => {
          return import(path.join(path.resolve(), routesFilePath))
        })
      )
      pages.push(...routes.flat(1))
    },
  },
})