From 21b397f0d6b96ec4875d3172f47533130bb08009 Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo Date: Thu, 14 May 2020 13:22:14 +0200 Subject: [PATCH] fix: don't use flat since it's not supported in node --- packages/core/src/getPathFromState.tsx | 5 ++--- packages/core/src/getStateFromPath.tsx | 14 ++++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/core/src/getPathFromState.tsx b/packages/core/src/getPathFromState.tsx index 9c800a94..e668262f 100644 --- a/packages/core/src/getPathFromState.tsx +++ b/packages/core/src/getPathFromState.tsx @@ -189,9 +189,8 @@ type ConfigItem = { }; function joinPaths(...paths: string[]): string { - return paths - .map((p) => p.split('/')) - .flat() + return ([] as string[]) + .concat(...paths.map((p) => p.split('/'))) .filter(Boolean) .join('/'); } diff --git a/packages/core/src/getStateFromPath.tsx b/packages/core/src/getStateFromPath.tsx index 2a626a14..5f7bdf92 100644 --- a/packages/core/src/getStateFromPath.tsx +++ b/packages/core/src/getStateFromPath.tsx @@ -64,9 +64,12 @@ export default function getStateFromPath( let initialRoutes: InitialRouteConfig[] = []; // Create a normalized configs array which will be easier to use - const configs = Object.keys(options) - .map((key) => createNormalizedConfigs(key, options, [], initialRoutes)) - .flat() + const configs = ([] as RouteConfig[]) + .concat( + ...Object.keys(options).map((key) => + createNormalizedConfigs(key, options, [], initialRoutes) + ) + ) .sort( (a, b) => // Sort configs so the most exhaustive is always first to be chosen @@ -232,9 +235,8 @@ export default function getStateFromPath( } function joinPaths(...paths: string[]): string { - return paths - .map((p) => p.split('/')) - .flat() + return ([] as string[]) + .concat(...paths.map((p) => p.split('/'))) .filter(Boolean) .join('/'); }