Некоторое время назад я столкнулся с подобной проблемой, и это сработало для Angular 4. Надеюсь, вы тоже сможете ее использовать.Это в app.component.ts :
export class AppComponent {
constructor(private router: Router, private route: ActivatedRoute, private location: Location) { }
private lastPoppedUrl: string;
private yScrollStack: number[] = [];
ngOnInit() {
const path = this.route.snapshot.queryParams['path'];
const navigateTo = '/' + path;
if (path) {
this.router.navigate([navigateTo]);
}
this.location.subscribe((ev: PopStateEvent) => {
this.lastPoppedUrl = ev.url;
});
this.router.events.subscribe((ev: any) => {
if (ev instanceof NavigationStart) {
if (ev.url != this.lastPoppedUrl)
this.yScrollStack.push(window.scrollY);
} else if (ev instanceof NavigationEnd) {
if (ev.url == this.lastPoppedUrl) {
this.lastPoppedUrl = undefined;
window.scrollTo(0, this.yScrollStack.pop());
} else
window.scrollTo(0, 0);
}
});
}
}