-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with nested routes using useBase #905
Comments
@ramsesgarate , I think you have used |
I can observe the same faulty behaviour. The pattern described at https://h3.unjs.io/guide/router#nested-routers also used two |
In my opinion, it's not a misbehavior. Based on the route matching logic, here's how it should work: For example: router.use('/api/**', useBase('/api/notes', notesRouter.handler)); If instead you intended to match '/api', you would set it up like this: router.use('/**', useBase('/api', notesRouter.handler)); |
Nvm, https://h3.unjs.io/examples/from-expressjs-to-h3 provides following example: /**
* h3 example app.
*/
import { createApp, createRouter, defineEventHandler, useBase } from "h3";
export const app = createApp();
const apiv1 = createRouter()
.get(
"/",
defineEventHandler(() => {
return "Hello from APIv1 root route.";
}),
)
.get(
"/users",
defineEventHandler(() => {
return "List of APIv1 users.";
}),
);
const apiv2 = createRouter()
.get(
"/",
defineEventHandler(() => {
return "Hello from APIv2 root route.";
}),
)
.get(
"/users",
defineEventHandler(() => {
return "List of APIv2 users.";
}),
);
app.use("/api/v1/**", useBase("/api/v1", apiv1.handler));
app.use("/api/v2/**", useBase("/api/v2", apiv2.handler)); So the expected behavior would be, that you can reach |
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: