File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -16,11 +16,25 @@ let updateRoot = hydrate({
16
16
// update the URL in the browser.
17
17
async function navigate ( pathname : string , push = false ) {
18
18
let res = fetchRSC < ReactElement > ( pathname . replace ( '.html' , '.rsc' ) ) ;
19
+ let currentPath = location . pathname ;
20
+ let [ newBasePath , newPathAnchor ] = pathname . split ( '#' ) ;
21
+
19
22
updateRoot ( res , ( ) => {
20
23
if ( push ) {
21
24
history . pushState ( null , '' , pathname ) ;
22
25
push = false ;
23
26
}
27
+
28
+ // Reset scroll if navigating to a different page without an anchor, primarily for the mobile case.
29
+ // Otherwise, make sure to scroll the anchor into view if any
30
+ if ( currentPath !== newBasePath && ! newPathAnchor ) {
31
+ window . scrollTo ( 0 , 0 ) ;
32
+ } else if ( newPathAnchor ) {
33
+ let element = document . getElementById ( newPathAnchor ) ;
34
+ if ( element ) {
35
+ element . scrollIntoView ( ) ;
36
+ }
37
+ }
24
38
} ) ;
25
39
}
26
40
You can’t perform that action at this time.
0 commit comments