Skip to content

Commit 113e5dc

Browse files
Merge pull request #2265 from nicholaspufal/fix-navigation-error
Fix history state errors
2 parents 37f9180 + 6d8ebea commit 113e5dc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/core/src/history.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ class History {
119119
public saveDocumentScrollPosition(scrollRegion: ScrollRegion): void {
120120
queue.add(() => {
121121
return Promise.resolve().then(() => {
122+
if (!window.history.state?.page) {
123+
return
124+
}
125+
122126
this.doReplaceState(
123127
{
124128
page: window.history.state.page,
@@ -131,11 +135,11 @@ class History {
131135
}
132136

133137
public getScrollRegions(): ScrollRegion[] {
134-
return window.history.state.scrollRegions || []
138+
return window.history.state?.scrollRegions || []
135139
}
136140

137141
public getDocumentScrollPosition(): ScrollRegion {
138-
return window.history.state.documentScrollPosition || { top: 0, left: 0 }
142+
return window.history.state?.documentScrollPosition || { top: 0, left: 0 }
139143
}
140144

141145
public replaceState(page: Page, cb: (() => void) | null = null): void {

0 commit comments

Comments
 (0)