Skip to content

Commit 9ce5af9

Browse files
authored
Merge pull request #20 from github/mp/custom-restore
allow customizing the restore condition
2 parents 21634da + 6f28385 commit 9ce5af9

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/core/drive/history.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export class History {
2121
started = false
2222
pageLoaded = false
2323
previousScrollRestoration?: ScrollRestoration
24+
// This can be customized by the consumer
25+
shouldRestore: (state: any) => boolean = () => true
2426

2527
constructor(delegate: HistoryDelegate) {
2628
this.delegate = delegate
@@ -94,7 +96,7 @@ export class History {
9496
onPopState = (event: PopStateEvent) => {
9597
if (this.shouldHandlePopState()) {
9698
const { turbo } = event.state || {}
97-
if (turbo) {
99+
if (this.shouldRestore(event.state) && turbo) {
98100
this.location = new URL(window.location.href)
99101
const { restorationIdentifier } = turbo
100102
this.restorationIdentifier = restorationIdentifier

0 commit comments

Comments
 (0)