File tree 3 files changed +25
-2
lines changed
3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -87,8 +87,13 @@ export class History {
87
87
this . location = new URL ( window . location . href )
88
88
const { restorationIdentifier, restorationIndex } = turbo
89
89
this . restorationIdentifier = restorationIdentifier
90
- const direction = restorationIndex > this . currentIndex ? "forward" : "back"
91
- this . delegate . historyPoppedToLocationWithRestorationIdentifierAndDirection ( this . location , restorationIdentifier , direction )
90
+ const direction = this . restorationVisitDirection ( restorationIdentifier , restorationIndex )
91
+
92
+ this . delegate . historyPoppedToLocationWithRestorationIdentifierAndDirection (
93
+ this . location ,
94
+ restorationIdentifier ,
95
+ direction
96
+ )
92
97
this . currentIndex = restorationIndex
93
98
}
94
99
}
@@ -109,4 +114,16 @@ export class History {
109
114
pageIsLoaded ( ) {
110
115
return this . pageLoaded || document . readyState == "complete"
111
116
}
117
+
118
+ restorationVisitDirection ( restorationIdentifier , restorationIndex ) {
119
+ const historyDirection = restorationIndex > this . currentIndex ? "forward" : "back"
120
+ const originalVisitDirection =
121
+ this . restorationData [ restorationIdentifier ] ?. direction === "back" ? "back" : "forward"
122
+
123
+ return historyDirection === "forward" ? originalVisitDirection : this . oppositeDirection ( originalVisitDirection )
124
+ }
125
+
126
+ oppositeDirection ( direction ) {
127
+ return direction === "forward" ? "back" : "forward"
128
+ }
112
129
}
Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ export function registerAdapter(adapter) {
34
34
* @param options Options to apply
35
35
* @param options.action Type of history navigation to apply ("restore",
36
36
* "replace" or "advance")
37
+ * @param options.direction Logical direction of the navigation, applies to
38
+ * view transitions ("forward", "back")
37
39
* @param options.historyChanged Specifies whether the browser history has
38
40
* already been changed for this visit or not
39
41
* @param options.referrer Specifies the referrer of this visit such that
Original file line number Diff line number Diff line change @@ -95,6 +95,10 @@ export class Session {
95
95
visit ( location , options = { } ) {
96
96
const frameElement = options . frame ? document . getElementById ( options . frame ) : null
97
97
98
+ if ( [ "forward" , "back" ] . includes ( options . direction ) ) {
99
+ this . history . updateRestorationData ( { direction : options . direction } )
100
+ }
101
+
98
102
if ( frameElement instanceof FrameElement ) {
99
103
const action = options . action || getVisitAction ( frameElement )
100
104
You can’t perform that action at this time.
0 commit comments