koa-tree-router icon indicating copy to clipboard operation
koa-tree-router copied to clipboard

Option for ignoring trailing slash

Open vlatkoodrljin opened this issue 3 years ago • 3 comments

It is useful sometimes not to return 404 if trailing slash exists but not explicitly in route pattern. What about adding ignoreTrailingSlash option while instancing for ignoring trailing slashes?

vlatkoodrljin avatar Aug 30 '22 19:08 vlatkoodrljin

Hi, I have added an option for trailing slash redirect in v0.11.0 under the option redirectTrailingSlash. Please try it when you have the time.

steambap avatar Sep 10 '22 07:09 steambap

It works but it would be more useful and efficient to have option only for ignoring trailing slash if exists on router level. Same like we have in find-my-way router module.

Something like this:

const router = new Router({
  ignoreTrailingSlash: true
});

const handler = function(ctx) {
  ctx.body = "hello, foo";
};

// maps "/foo/" and "/foo" to `handler`
router.get("/foo", handler); or router.get("/foo/", handler);

What do you think?

vlatkoodrljin avatar Sep 10 '22 08:09 vlatkoodrljin

Sorry, I misunderstand your request last weekend. I have added ignoreTrailingSlash in v0.12.0.

steambap avatar Sep 15 '22 12:09 steambap