Skip to content

Commit

Permalink
EZQMS-642: Extended navigate() signature to support History replace…
Browse files Browse the repository at this point in the history
…ment (#4979)

Signed-off-by: Petr Vyazovetskiy <develop.pit@gmail.com>
  • Loading branch information
anotherpit authored Mar 15, 2024
1 parent 487d753 commit 8ead1c4
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/ui/src/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ead1c4

Please sign in to comment.