Skip to content

Instantly share code, notes, and snippets.

@jugyo
Created October 22, 2019 22:07
Show Gist options
  • Save jugyo/d251fe99687b99ac49fab8cbcd47bf48 to your computer and use it in GitHub Desktop.
Save jugyo/d251fe99687b99ac49fab8cbcd47bf48 to your computer and use it in GitHub Desktop.
...
export class AppModule {
constructor(router: Router, viewportScroller: ViewportScroller) {
router.events.pipe(filter((e) => e instanceof Scroll)).subscribe((e: any) => {
if (e.position) {
// backward navigation
setTimeout(() => {
viewportScroller.scrollToPosition(e.position);
}, 100);
} else if (e.anchor) {
// anchor navigation
viewportScroller.scrollToAnchor(e.anchor);
} else {
// forward navigation
viewportScroller.scrollToPosition([0, 0]);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment