steambap / koa-tree-router

high performance router for Koa
MIT License
138 stars 11 forks source link

Option for ignoring trailing slash #25

Closed vlatkoodrljin closed 2 years ago

vlatkoodrljin commented 2 years ago

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?

steambap commented 2 years ago

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.

vlatkoodrljin commented 2 years ago

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?

steambap commented 2 years ago

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