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

Multi routers #936

Closed
Maxttier opened this issue Dec 25, 2024 · 5 comments
Closed

Multi routers #936

Maxttier opened this issue Dec 25, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@Maxttier
Copy link
Contributor

Environment

latest

Reproduction

app = createApp()
router = createRouter()
router2 = createRouter()
app.use(router)
app.use(router2)

Describe the bug

Not work at moment. I do something bad or it is not permitted?

Additional context

No response

Logs

No response

@Maxttier Maxttier added the bug Something isn't working label Dec 25, 2024
@Maxttier
Copy link
Contributor Author

Maxttier commented Dec 25, 2024

or need to be

import { createH3, redirect, withBase } from "h3";
// Init App
export const app = createH3({ debug: true });
// Main Router
app.use("/", (event) => redirect(event, "/api/test"));
const apiRouter = createH3();
// Nested API Router
app.use("/api/**", withBase("/api", apiRouter.handler));
apiRouter.use("/test", () => "API /test");
?

app.use("/api/", withBase("/api", apiRouter.handler));
app.use("/api2/
", withBase("/api2", apiRouter.handler));

@Maxttier
Copy link
Contributor Author

Maxttier commented Dec 25, 2024

withBase is undefined

useBase: Migrate to withbase.

@Maxttier
Copy link
Contributor Author

    const apiRouter = createRouter();
    apiRouter.use("/test", () => "API /test");

    // Nested API Router
    h3App.use(
            "/api/**", 
            h3_1.useBase("/api", apiRouter.handler)
    );

Not work

@Maxttier
Copy link
Contributor Author

Work

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

@Maxttier
Copy link
Contributor Author

How to get all routes form app.router and h3App? Because app.router.stack is empty app.stack show only

 {
    route: "/",
    match: undefined,
    handler: [Function],
  }, {
    route: "/",
    match: undefined,
    handler: [Function],
  }, {
    route: "/",
    match: undefined,
    handler: [Function],
  }


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant