From 20e0518d4abf493ffd6d8a41d766c8559b6308b9 Mon Sep 17 00:00:00 2001 From: Momchil Atanasov Date: Fri, 2 Jul 2021 11:32:30 +0300 Subject: [PATCH] Skip query params with null or undefined value --- src/__tests__/actionToPath.test.js | 3 ++- src/core.js | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/__tests__/actionToPath.test.js b/src/__tests__/actionToPath.test.js index 0799d77..f0fbadf 100644 --- a/src/__tests__/actionToPath.test.js +++ b/src/__tests__/actionToPath.test.js @@ -36,7 +36,8 @@ describe('actionToPath', () => { expect( actionToPath( routesMap, - navigate('PROJECT', { projectName: 'Project 123' }, { query: { returnTo: 'home' } }) + navigate('PROJECT', { projectName: 'Project 123' }, + { query: { returnTo: 'home', missing: undefined, unspecified: null } }) ) ).toEqual({ pathname: '/portal/projects/Project%20123', diff --git a/src/core.js b/src/core.js index 52a524e..e2084ae 100644 --- a/src/core.js +++ b/src/core.js @@ -31,6 +31,9 @@ function stringifyQuery(query) { const params = new URLSearchParams(); for (const key in query) { const val = query[key]; + if (val === undefined || val === null) { + continue; + } if (Array.isArray(val)) { for (const _val of val) { params.append(key, _val);