EZQMS-642: Extended navigate() signature to support History replacement (#4979)

Signed-off-by: Petr Vyazovetskiy <develop.pit@gmail.com>
This commit is contained in:
Pete Anøther 2024-03-15 16:13:57 -03:00 committed by GitHub
parent 487d753a9a
commit 8ead1c4ab8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -170,22 +170,22 @@ export function setLocationStorageKey (storageKey: string): void {
locationStorageKeyId = storageKey locationStorageKeyId = storageKey
} }
export function navigate (location: PlatformLocation, store = true): boolean { export function navigate (location: PlatformLocation, replace = false): boolean {
closePopup() closePopup()
const cur = locationToUrl(getCurrentLocation()) const cur = locationToUrl(getCurrentLocation())
const url = locationToUrl(location) const url = locationToUrl(location)
if (cur !== url) { if (cur !== url) {
if (store) { const data = !embeddedPlatform ? null : { location }
if (!embeddedPlatform) { const _url = !embeddedPlatform ? url : undefined
history.pushState(null, '', url) if (replace) {
history.replaceState(data, '', _url)
} else { } else {
history.pushState({ location }, '') history.pushState(data, '', _url)
} }
localStorage.setItem(locationStorageKeyId, JSON.stringify(location)) localStorage.setItem(locationStorageKeyId, JSON.stringify(location))
if (location.path[1] !== undefined) { if (location.path[1] !== undefined) {
localStorage.setItem(`${locationStorageKeyId}_${location.path[1]}`, JSON.stringify(location)) localStorage.setItem(`${locationStorageKeyId}_${location.path[1]}`, JSON.stringify(location))
} }
}
locationWritable.set(location) locationWritable.set(location)
return true return true
} }