From 8ead1c4ab8df29737bef5677cdde14d6f5aca04d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pete=20An=C3=B8ther?= Date: Fri, 15 Mar 2024 16:13:57 -0300 Subject: [PATCH] EZQMS-642: Extended `navigate()` signature to support History replacement (#4979) Signed-off-by: Petr Vyazovetskiy --- packages/ui/src/location.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/ui/src/location.ts b/packages/ui/src/location.ts index d92a6638582..6aa819b093b 100644 --- a/packages/ui/src/location.ts +++ b/packages/ui/src/location.ts @@ -170,21 +170,21 @@ export function setLocationStorageKey (storageKey: string): void { locationStorageKeyId = storageKey } -export function navigate (location: PlatformLocation, store = true): boolean { +export function navigate (location: PlatformLocation, replace = false): boolean { closePopup() const cur = locationToUrl(getCurrentLocation()) const url = locationToUrl(location) if (cur !== url) { - if (store) { - if (!embeddedPlatform) { - history.pushState(null, '', url) - } else { - history.pushState({ location }, '') - } - localStorage.setItem(locationStorageKeyId, JSON.stringify(location)) - if (location.path[1] !== undefined) { - localStorage.setItem(`${locationStorageKeyId}_${location.path[1]}`, JSON.stringify(location)) - } + const data = !embeddedPlatform ? null : { location } + const _url = !embeddedPlatform ? url : undefined + if (replace) { + history.replaceState(data, '', _url) + } else { + history.pushState(data, '', _url) + } + localStorage.setItem(locationStorageKeyId, JSON.stringify(location)) + if (location.path[1] !== undefined) { + localStorage.setItem(`${locationStorageKeyId}_${location.path[1]}`, JSON.stringify(location)) } locationWritable.set(location) return true