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

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,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