Skip to content

Commit

Permalink
Skip query params with null or undefined value
Browse files Browse the repository at this point in the history
  • Loading branch information
mokiat authored and sachmata committed Jul 2, 2021
1 parent ada4727 commit 20e0518
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/__tests__/actionToPath.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 20e0518

Please # to comment.