Skip to content
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

Nested route only works with double slashs at end??????? #708

Open
silvercent011 opened this issue Mar 18, 2024 · 6 comments
Open

Nested route only works with double slashs at end??????? #708

silvercent011 opened this issue Mar 18, 2024 · 6 comments

Comments

@silvercent011
Copy link

Environment

h3 - 1.11.1
node - 18

Reproduction

import { createApp, createRouter, defineEventHandler, useBase } from "h3";

export const app = createApp();

const router = createRouter();

const apiRouter = createRouter();

apiRouter.get(
  "/",
  defineEventHandler((event) => {
    console.log("Hello from router!");
    return { message: "Hello from router!" };
  })
);

router.use("/api/**", useBase("/api", apiRouter.handler));

app.use(router);

Describe the bug

The nested router, only works if the path have two slashes at end of url, http://localhost:3000/api//, without double slash, throw a 404 error.

Additional context

No response

Logs

No response

@NozomuIkuta
Copy link
Member

Would you provide a minimal reproduction instead of just showing the code?
Although you seem to have just copied and modified the code from documentation, runnable reproduction is much helpful for maintainers. 🙌

You can use StackBlitz, for example.

One of benefits of providing it is that we could folk your code and share fixed version if it's just a mistake.
Otherwise, we will dig into the issue.

@silvercent011
Copy link
Author

https://stackblitz.com/edit/stackblitz-starters-krifhq?file=src%2Fapp.ts

@NozomuIkuta
Copy link
Member

Thank you for providing the reproduction!!
Now it's much easier to debug! 🙏

As far as I checked, there seems to be a bug in h3 routing.
The root cause would exist in useBase of h3, or unjs/radix3#84 might be related.

At the moment, one workaround is to stop using top-level router and let api router look up its routes.

https://stackblitz.com/edit/stackblitz-starters-ygfkoc?file=src%2Fapp.ts

@silvercent011
Copy link
Author

ok, thanks for the support @NozomuIkuta :)

Should I close the issue or leave it open for resolution of the bug/documentation/or similar?

@NozomuIkuta
Copy link
Member

My pleasure.
Would you keep it open for governance so that author can recognize this issue?

@silvercent011
Copy link
Author

Yep!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants