File tree 3 files changed +21
-3
lines changed
3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -87,8 +87,19 @@ 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
+
91
+ let direction
92
+ if ( restorationIndex > this . currentIndex ) {
93
+ direction = this . restorationData [ restorationIdentifier ] ?. direction === "back" ? "back" : "forward"
94
+ } else {
95
+ direction = this . restorationData [ restorationIdentifier ] ?. direction === "back" ? "forward" : "back"
96
+ }
97
+
98
+ this . delegate . historyPoppedToLocationWithRestorationIdentifierAndDirection (
99
+ this . location ,
100
+ restorationIdentifier ,
101
+ direction
102
+ )
92
103
this . currentIndex = restorationIndex
93
104
}
94
105
}
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 ( 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
@@ -250,8 +254,9 @@ export class Session {
250
254
followedLinkToLocation ( link , location ) {
251
255
const action = this . getActionForLink ( link )
252
256
const acceptsStreamResponse = link . hasAttribute ( "data-turbo-stream" )
257
+ const direction = link . getAttribute ( "data-turbo-visit-direction" )
253
258
254
- this . visit ( location . href , { action, acceptsStreamResponse } )
259
+ this . visit ( location . href , { action, acceptsStreamResponse, direction } )
255
260
}
256
261
257
262
// Navigator delegate
You can’t perform that action at this time.
0 commit comments