Angular 5 Scroll To Top On Every Route Click
Answer : There are some solutions, make sure to check them all :) The router outlet will emit the activate event any time a new component is being instantiated, so we could use (activate) to scroll (for example) to the top: app.component.html <router-outlet (activate)="onActivate($event)" ></router-outlet> app.component.ts onActivate(event) { window.scroll(0,0); //or document.body.scrollTop = 0; //or document.querySelector('body').scrollTo(0,0) ... } Use, for exemple, this solution for a smooth scroll: onActivate(event) { let scrollToTop = window.setInterval(() => { let pos = window.pageYOffset; if (pos > 0) { window.scrollTo(0, pos - 20); // how far to scroll on each step } else { window.clearInterval(scrollToTop); } }, 16); } If you wish to be selective, say not every component should trigger the scrolling, you can ...