From 4ce62b26a8bb7fad0f704c3c4c4b8e4b03b110b5 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 15 Mar 2021 08:45:56 -0700 Subject: [PATCH] fix(router): simplify param merging (#22999) --- core/src/components/router/utils/matching.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/core/src/components/router/utils/matching.ts b/core/src/components/router/utils/matching.ts index 90f1e99877..7b92df06d1 100644 --- a/core/src/components/router/utils/matching.ts +++ b/core/src/components/router/utils/matching.ts @@ -82,18 +82,10 @@ export const matchesPath = (inputPath: string[], chain: RouteChain): RouteChain return chain; }; -export const mergeParams = (a: any, b: any): any => { - if (!a && b) { - return b; - } else if (a && !b) { - return a; - } else if (a && b) { - return { - ...a, - ...b - }; - } - return undefined; +// Merges the route parameter objects. +// Returns undefined when both parameters are undefined. +export const mergeParams = (a: {[key: string]: any} | undefined, b: {[key: string]: any} | undefined): {[key: string]: any} | undefined => { + return a || b ? { ...a, ...b } : undefined; }; export const routerIDsToChain = (ids: RouteID[], chains: RouteChain[]): RouteChain | null => {