diff --git a/client/luigi-client.js b/client/luigi-client.js index 2bef10dcc4..21d3b975ca 100644 --- a/client/luigi-client.js +++ b/client/luigi-client.js @@ -126,7 +126,6 @@ _callAllFns(_onInitFns, currentContext.context); } else if ('luigi.navigate' === e.data.msg) { setContext(e.data); - if (!currentContext.internal.isNavigateBack) { var hashRoutingModeActive = e.data.viewUrl.indexOf('#') !== -1 && diff --git a/core/src/App.html b/core/src/App.html index dd6813c87e..f5f0f50226 100644 --- a/core/src/App.html +++ b/core/src/App.html @@ -217,12 +217,11 @@ if ('luigi.navigation.open' === e.data.msg) { this.set({ isNavigateBack: false }); - handleNavigation(this, e.data, config); + await handleNavigation(this, e.data, config); } if ('luigi.navigation.back' === e.data.msg) { // go back: context from the view - this.set({ isNavigateBack: false }); const preservedViews = this.get().preservedViews; if (preservedViews && preservedViews.length) { // remove current active iframe and data @@ -238,11 +237,12 @@ }); // TODO: check if handleNavigation or history pop to update hash / path - handleNavigation( + await handleNavigation( this, { params: { link: previousActiveIframeData.path } }, config ); + this.set({ goBackContext: undefined, isNavigateBack: false }); } else { console.error('goBack() not possible, no preserved views found.'); } diff --git a/core/src/services/routing.js b/core/src/services/routing.js index 7458fb8826..794c5fe2a1 100644 --- a/core/src/services/routing.js +++ b/core/src/services/routing.js @@ -218,8 +218,6 @@ const navigateIframe = (config, component, node) => { }, '*' ); - // clear goBackContext after sending it to the client - component.set({ goBackContext: undefined }); /** * check if luigi responded @@ -411,16 +409,14 @@ export const matchPath = async path => { navigateTo used for navigation @param route string absolute path of the new route @param options object navi options, eg preserveView - @param windowElem object defaults to window - @param documentElem object defaults to document */ -export const navigateTo = async (route, windowElem = window) => { +export const navigateTo = async route => { if (LuigiConfig.getConfigValue('routing.useHashRouting')) { - windowElem.location.hash = route; + window.location.hash = route; return; } - windowElem.history.pushState( + window.history.pushState( { path: route }, @@ -439,7 +435,7 @@ export const navigateTo = async (route, windowElem = window) => { event = new CustomEvent('popstate'); } - windowElem.dispatchEvent(event); + window.dispatchEvent(event); }; export const buildFromRelativePath = path => { @@ -450,21 +446,21 @@ export const buildFromRelativePath = path => { } }; -export const handleRouteClick = (node, windowElem = window) => { +export const handleRouteClick = node => { if (node.externalLink && node.externalLink.url) { node.externalLink.sameWindow - ? (windowElem.location.href = node.externalLink.url) - : windowElem.open(node.externalLink.url).focus(); + ? (window.location.href = node.externalLink.url) + : window.open(node.externalLink.url).focus(); // externalLinkUrl property is provided so there's no need to trigger routing mechanizm return; } else if (node.link) { const link = node.link.startsWith('/') ? node.link : buildFromRelativePath(node.link); - navigateTo(link, windowElem); + navigateTo(link); return; } else { const route = buildRoute(node, `/${node.pathSegment}`); - navigateTo(route, windowElem); + navigateTo(route); } }; diff --git a/core/test/services/routing.spec.js b/core/test/services/routing.spec.js index f7f2b81bda..f768d25102 100644 --- a/core/test/services/routing.spec.js +++ b/core/test/services/routing.spec.js @@ -516,7 +516,7 @@ describe('Routing', () => { LuigiConfig.getConfigValue.returns(true); // when - routing.handleRouteClick(nodeWithParent, window, document); + routing.handleRouteClick(nodeWithParent); // then assert.equal(window.location.hash, expectedRoute); @@ -528,7 +528,7 @@ describe('Routing', () => { LuigiConfig.getConfigValue.returns(true); // when - routing.handleRouteClick(nodeWithoutParent, window); + routing.handleRouteClick(nodeWithoutParent); // then assert.equal(window.location.hash, expectedRoute); @@ -545,7 +545,7 @@ describe('Routing', () => { LuigiConfig.getConfigValue.returns(false); // when - routing.handleRouteClick(nodeWithParent, window); + routing.handleRouteClick(nodeWithParent); // then const pushStateArgs = window.history.pushState.args[0]; @@ -566,7 +566,7 @@ describe('Routing', () => { LuigiConfig.getConfigValue.returns(false); // when - routing.handleRouteClick(nodeWithoutParent, window, document); + routing.handleRouteClick(nodeWithoutParent); // then const pushStateArgs = window.history.pushState.args[0]; @@ -584,11 +584,10 @@ describe('Routing', () => { window.history.pushState = sinon.spy(); window.dispatchEvent = sinon.spy(); const dispatchCallsNum = window.dispatchEvent.callCount; - - // when LuigiConfig.getConfigValue.returns(false); - routing.handleRouteClick(nodeWithoutParent, window, document); + // when + routing.handleRouteClick(nodeWithoutParent); // then const pushStateArgs = window.history.pushState.args[0];