You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attempting to set up nested routes using useBase in h3, the route notesRouter.get('/') does not respond as expected, while other routes, such as notesRouter.get('/get'), work correctly.
Steps to Reproduce:
Create an application with h3.
Define a main route using createRouter and a nested route with useBase for notesRouter.
In notesRouter, define two routes: '/get' and '/'.
Make a request to '/api/notes/' and observe the behavior.
The route notesRouter.get('/') should respond as expected, similar to notesRouter.get('/get'), allowing for a complete RESTful API structure.
Additional context
import{createApp,createRouter,useBase}from'h3';// Init Appexportconstapp=createApp({debug: true});// Main Routerconstrouter=createRouter();router.use('/',(event)=>` <h1>Nested routes</h1> <ul> <li>Works: <a href="/api/notes/get">/api/notes/get</a></li> <li>Not working: <a href="/api/notes/">/api/notes/</a></li> </ul> `);app.use(router);constnotesRouter=createRouter();router.use('/api/notes/**',useBase('/api/notes',notesRouter.handler));notesRouter.get('/get',()=>'<h1>Nested routes works /api/notes/get</h1><a href="/">Home</a>');notesRouter.get('/',()=>'<h1>Nested routes not working /api/notes/</h1><a href="/">Home</a>');
Logs
No response
The text was updated successfully, but these errors were encountered:
I can observe the same faulty behaviour. The pattern described at https://h3.unjs.io/guide/router#nested-routers also used two createRouter. The "/" route of the child router can only be called at the moment when you add a second "/" to the requested URL (like "/api/notes//" in the demo above).
Environment
Node: 22.10.0
h3: 1.13.0
Windows 11
Reproduction
https://stackblitz.com/edit/github-ihqa9f?file=app.ts
Describe the bug
When attempting to set up nested routes using useBase in h3, the route notesRouter.get('/') does not respond as expected, while other routes, such as notesRouter.get('/get'), work correctly.
Steps to Reproduce:
The route
notesRouter.get('/')
should respond as expected, similar tonotesRouter.get('/get')
, allowing for a complete RESTful API structure.Additional context
Logs
No response
The text was updated successfully, but these errors were encountered: