1

I use koa-router, and would like to match part of the URL (potentially) including slashes. For instance, everything that matches /foo/xxx, /foo/yyy, /foo/dir/xxx, and /foo/a/b/c/d.

Something like the following, if *path meant the same as ":path but including slashes":

router.get('/foo/*path', async (ctx) => {
    console.log(`PATH: ${ctx.params.path}`);
});

Being able to say "catch everything starting with /foo/" would work as well.

I am stuck here, I don't find any way for koa-router to allow me to do this.

Florent Georges
  • 2,190
  • 1
  • 15
  • 24
  • Can you tell me which version of koa router you are using by looking at your `package.json` file? I have been using `@koa/router` and can simply do `router.get('/foo/:splat*', async (ctx) => {});` to achieve what you might be looking for. – Rubek Joshi Nov 02 '22 at 12:54
  • 1
    @RubekJoshi Yes, that's it, thank you! I just can't find this anywhere in the documentation... If you turn your comment into an answer, I'll accept it. – Florent Georges Nov 04 '22 at 10:46

1 Answers1

1

I found the answer in one of koa's github issue. You need to simply create your router as follows:

router.get('/foo/:splat*', async (ctx) => {
  // do what you want
});
Rubek Joshi
  • 562
  • 7
  • 22