8000 Improve `matchedRoute` for nested apps · Issue #1110 · h3js/h3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Improve matchedRoute for nested apps #1110
Open
@itssimon

Description

@itssimon

Describe the feature

For nested apps, the matchedRoute context variable only includes the route within the nested app and omits the wildcard route in the main app that matched first.

Say for an app like this:

  const app = new H3();
  const nestedApp = new H3();
  app.all("/api/**", withBase("/api", nestedApp.handler));

  nestedApp.get(
    "/hello/:id",
    defineEventHandler((event) => {
      const id = getRouterParam(event, "id");
      return `Hello ${id}!`;
    }),
  );

The matchedRoute read within a middleware/plugin would be:

{
  method: "GET",
  route: "/hello/:id",
  handler: function() { ... },
  middleware: undefined,
}

It would be great if there was also a reference to the /api/** route in the main app, so that one can construct the full route path for events, in this case /api/hello/:id.

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0