Skip to Content
Senri
Routing

Wildcards

Match a path and everything under it with *

Make the last segment * to match that path and everything under it. The rest of the path is in "*".

.("/docs/*", ({ "*":  }) => `page: ${}`);
.("/users/:id/files/*", ({ , "*":  }) => `${}: ${}`);
.("/*", (, ) => .());   // SPA fallback (also matches /)
Request to /docs/*"*"
/docs, /docs/""
/docs/a, /docs/a/, /docs//a"a"
/docs/a/b"a/b"
/docsxNo match

Where you can write it

* can only be the whole last segment. /a/*/c, /*.js, /files* and /*name are errors when registering.

Not counted for 405 and OPTIONS

A POST or OPTIONS request to a path that only has GET /docs/* is 404. To answer it, register app.post, app.options or app.all.

Do not use the value as a file path

The value of "*" can contain \, : and NUL (for /docs/..%5C..%5Csecret it is ..\..\secret). To serve files, use serveStatic(), which checks for these.

  • The value is decoded once per segment. Do not decode it again (%252F stays %2F)
  • In middleware, app.use("/docs/*", mw) means the same as app.use("/docs", mw)

On this page