Fix desktop app history navigation (#3611)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2023-08-21 18:27:42 +07:00 committed by GitHub
parent 0dd2fe3d72
commit d0b3a48b6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -122,6 +122,12 @@ if (!embeddedPlatform) {
window.addEventListener('popstate', () => {
locationWritable.set(getRawCurrentLocation())
})
} else {
window.addEventListener('popstate', (state) => {
if (state.state.location !== undefined) {
locationWritable.set(state.state.location)
}
})
}
export const location = derived(locationWritable, (loc) => justClone(loc))
@ -167,6 +173,8 @@ export function navigate (location: PlatformLocation, store = true): boolean {
if (store) {
if (!embeddedPlatform) {
history.pushState(null, '', url)
} else {
history.pushState({ location }, '')
}
localStorage.setItem(locationStorageKeyId, JSON.stringify(location))
if (location.path[1] !== undefined) {