Skip to content

Commit 78b4d85

Browse files
committed
fix(router): Scroll restoration should use instant scroll behavior for traversals
When the scroll position is being restored, this change upates the behavior to use 'instant' rather than the default 'auto', which will be whatever the browser behavior is for 'window.scrollTo'. The 'smooth' behavior does not match how browsers behavior when performing a traversal navigation for MPAs, which is 'instant'. related to #58258
1 parent 20bb459 commit 78b4d85

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/router/src/router_scroller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,13 @@ export class RouterScroller implements OnDestroy {
8585
private consumeScrollEvents() {
8686
return this.transitions.events.subscribe((e) => {
8787
if (!(e instanceof Scroll)) return;
88+
const instantScroll: ScrollOptions = {behavior: 'instant'};
8889
// a popstate event. The pop state event will always ignore anchor scrolling.
8990
if (e.position) {
9091
if (this.options.scrollPositionRestoration === 'top') {
91-
this.viewportScroller.scrollToPosition([0, 0]);
92+
this.viewportScroller.scrollToPosition([0, 0], instantScroll);
9293
} else if (this.options.scrollPositionRestoration === 'enabled') {
93-
this.viewportScroller.scrollToPosition(e.position);
94+
this.viewportScroller.scrollToPosition(e.position, instantScroll);
9495
}
9596
// imperative navigation "forward"
9697
} else {

0 commit comments

Comments
 (0)