diff --git a/core/src/core-api/routing.js b/core/src/core-api/routing.js index 94844a21cf..5f5d209038 100644 --- a/core/src/core-api/routing.js +++ b/core/src/core-api/routing.js @@ -73,7 +73,7 @@ class LuigiRouting { searchParams.set(paramKey, value); if (value === undefined) { - searchParams.delete(key); + searchParams.delete(paramKey); } } } diff --git a/core/test/core-api/routing.spec.js b/core/test/core-api/routing.spec.js index 1e54b6ebdb..b5e989e14a 100644 --- a/core/test/core-api/routing.spec.js +++ b/core/test/core-api/routing.spec.js @@ -59,12 +59,18 @@ describe('Luigi routing', function() { LuigiRouting.addSearchParams('bar', true); sinon.assert.calledWith(console.log, 'Params argument must be an object'); }); - it('delete search params from url', () => { + it('delete search params from url with keepBrowserHistory is true', () => { window.state = {}; global.location = 'http://some.url.de?luigi=rocks&mario=red'; LuigiRouting.addSearchParams({ mario: undefined }, true); sinon.assert.calledWithExactly(window.history.pushState, window.state, '', 'http://some.url.de/?luigi=rocks'); }); + it('delete search params from url with keepBrowserHistory is false', () => { + window.state = {}; + global.location = 'http://some.url.de?luigi=rocks&mario=red'; + LuigiRouting.addSearchParams({ mario: undefined }, false); + sinon.assert.calledWithExactly(window.history.replaceState, window.state, '', 'http://some.url.de/?luigi=rocks'); + }); }); describe('SearchParams hash routing', () => { beforeEach(() => { @@ -182,5 +188,15 @@ describe('Luigi routing', function() { LuigiRouting.addNodeParams('bar', true); sinon.assert.calledWith(console.log, 'Params argument must be an object'); }); + it('remove node param if value of params object is undefined', ()=>{ + window.state = {}; + global.location = 'http://some.url.de'; + LuigiRouting.addNodeParams({ test: undefined }, false); + sinon.assert.calledWithExactly(window.history.replaceState, window.state, '', 'http://some.url.de/'); + LuigiRouting.addNodeParams({ foo: 'bar' }, false); + sinon.assert.calledWithExactly(window.history.replaceState, window.state, '', 'http://some.url.de/?%7Efoo=bar'); + LuigiRouting.addNodeParams({ foo: undefined }, false); + sinon.assert.calledWithExactly(window.history.replaceState, window.state, '', 'http://some.url.de/'); + }); }); });