From 35aaf15c8d6e5079f6b3822b463907aa5a33df3f Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 9 Jul 2024 13:02:45 +0200 Subject: [PATCH] refactor: makes params matching opt-out always --- src/operations/find-all.ts | 2 +- src/operations/find.ts | 12 ++++-------- test/bench/impl.ts | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/operations/find-all.ts b/src/operations/find-all.ts index 246a7f8..978757f 100644 --- a/src/operations/find-all.ts +++ b/src/operations/find-all.ts @@ -20,7 +20,7 @@ export function findAllRoutes( matches.push({ data: match.data, params: - opts?.params && match.paramsMap + match.paramsMap && opts?.params !== false ? getMatchParams(segments, match.paramsMap) : undefined, }); diff --git a/src/operations/find.ts b/src/operations/find.ts index 05566a2..57ef0be 100644 --- a/src/operations/find.ts +++ b/src/operations/find.ts @@ -31,16 +31,12 @@ export function findRoute( return; } - if (opts?.params || !match.paramsMap) { - return { - data: match.data, - params: undefined, - }; - } - return { data: match.data, - params: getMatchParams(segments, match.paramsMap), + params: + match.paramsMap && opts?.params !== false + ? getMatchParams(segments, match.paramsMap) + : undefined, }; } diff --git a/test/bench/impl.ts b/test/bench/impl.ts index a353220..77ba26d 100644 --- a/test/bench/impl.ts +++ b/test/bench/impl.ts @@ -27,7 +27,7 @@ export function createRouter(rou3: typeof rou3Src, withAll: boolean = false) { } if (withAll) { return (method: string, path: string) => { - return rou3.findAllRoutes(router, method, path, { params: true }).pop(); + return rou3.findAllRoutes(router, method, path).pop(); }; } return (method: string, path: string) => {