Skip to content

Commit e6d737f

Browse files
committed
Fix history navigation issue
1 parent 6913cd4 commit e6d737f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

packages/core/src/router.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
} from './types'
3232
import { hrefToUrl, mergeDataIntoQueryString, urlWithoutHash } from './url'
3333

34+
const isChromeIOS = /CriOS/.test(navigator.userAgent)
3435
const isServer = typeof window === 'undefined'
3536
const cloneSerializable = <T>(obj: T): T => JSON.parse(JSON.stringify(obj))
3637
const nextFrame = (callback: () => void) => {
@@ -494,14 +495,24 @@ export class Router {
494495

495496
protected pushState(page: Page): void {
496497
this.page = page
497-
// Defer history.pushState to the next event loop tick to prevent timing conflicts.
498-
// Ensure any previous history.replaceState completes before pushState is executed.
499-
setTimeout(() => window.history.pushState(cloneSerializable(page), '', page.url))
498+
if (isChromeIOS) {
499+
// Defer history.pushState to the next event loop tick to prevent timing conflicts.
500+
// Ensure any previous history.replaceState completes before pushState is executed.
501+
setTimeout(() => window.history.pushState(cloneSerializable(page), '', page.url))
502+
} else {
503+
window.history.pushState(cloneSerializable(page), '', page.url)
504+
}
500505
}
501506

502507
protected replaceState(page: Page): void {
503508
this.page = page
504-
window.history.replaceState(cloneSerializable(page), '', page.url)
509+
if (isChromeIOS) {
510+
// Defer history.replaceState to the next event loop tick to prevent timing conflicts.
511+
// Ensure any previous history.pushState completes before replaceState is executed.
512+
setTimeout(() => window.history.replaceState(cloneSerializable(page), '', page.url))
513+
} else {
514+
window.history.replaceState(cloneSerializable(page), '', page.url)
515+
}
505516
}
506517

507518
protected handlePopstateEvent(event: PopStateEvent): void {

0 commit comments

Comments
 (0)