From 44616dd45aa3a282118674210b0a0773211a6c51 Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Tue, 14 Nov 2017 17:28:52 +0100 Subject: [PATCH] fix 2953 (#2976) --- src/routers/StackRouter.js | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/routers/StackRouter.js b/src/routers/StackRouter.js index 5ef5588..c23813b 100644 --- a/src/routers/StackRouter.js +++ b/src/routers/StackRouter.js @@ -30,6 +30,14 @@ function _getUuid() { return `${uniqueBaseId}-${uuidCount++}`; } +function isEmpty(obj: ?Object): boolean { + if (!obj) return true; + for (let key in obj) { + return false; + } + return true; +} + export default ( routeConfigs: NavigationRouteConfigMap, stackConfig: NavigationStackRouterConfig = {} @@ -375,17 +383,17 @@ export default ( // reduce the items of the query string. any query params may // be overridden by path params - const queryParams = - inputParams || - (queryString || '').split('&').reduce((result: *, item: string) => { - if (item !== '') { - const nextResult = result || {}; - const [key, value] = item.split('='); - nextResult[key] = value; - return nextResult; - } - return result; - }, null); + const queryParams = !isEmpty(inputParams) + ? inputParams + : (queryString || '').split('&').reduce((result: *, item: string) => { + if (item !== '') { + const nextResult = result || {}; + const [key, value] = item.split('='); + nextResult[key] = value; + return nextResult; + } + return result; + }, null); // reduce the matched pieces of the path into the params // of the route. `params` is null if there are no params.