Hello.
Original discussion here: #routing message
I'm in Nuxt, and trying to get an H3 router working on an api folder using the following path /server/api/foo/[...].ts – with mixed fortunes:
import {
createRouter,
eventHandler,
useBase,
getRouterParams,
} from 'h3'
const router = createRouter()
router
// these don't work
.get('', eventHandler(() => {
return 'nothing'
}))
.get('/', eventHandler(() => {
return 'slash'
}))
// these do work
.get('/test', eventHandler(() => {
return 'test'
}))
.get('/hello/:name', eventHandler(event => {
const { name } = getRouterParams(event)
return `Hello ${name}`
}))
export default useBase('/api/foo', router.handler)
Whilst routes with slugs (/api/foo/test/) work, the index route (/api/foo/) is not picked up by Nitro:
This localhost page can’t be found
No web page was found for the web address: http://localhost:3333/api/foo/
The only workaround I could seem to find was creating a separate index file outside of the catch-all file:
+- api
+- foo
+- index.get.ts <-- /api/foo
+- [...].ts <-- /api/foo/*
I've also tried various combinations of brackets, nested brackets, dots, slugs, dots and slugs and brackets, but no luck.
Note that Nuxt /pages a [...].vue file does seem to catch index and slug routes.
Also, I've checked that routing including the index works in h3, and it does:
So this a Nuxt routes oversight, a bug or by design?