Fixed a small issue with the smooth-scroll
This commit is contained in:
parent
8e92ba96e8
commit
7837a0958d
|
@ -9,6 +9,7 @@ export class SmoothScroll {
|
|||
private interval;
|
||||
private readonly sub;
|
||||
private lastRoute;
|
||||
private whitelist = ['/continent', '/country']
|
||||
|
||||
constructor(private router: Router) {
|
||||
if(typeof window !== "undefined") {
|
||||
|
@ -19,13 +20,7 @@ export class SmoothScroll {
|
|||
}
|
||||
const fragment = router.parseUrl(router.url).fragment;
|
||||
if (this.lastRoute !== this.getUrl(event.url)) {
|
||||
// console.log('event.url', event.url);
|
||||
// window.scrollTo({top: 0});
|
||||
if (!this.lastRoute || (!this.lastRoute.includes('/continent') && !this.lastRoute.includes('/country'))
|
||||
|| (!event.url.includes('/continent') && !event.url.includes('/country'))) {
|
||||
console.log('event.url', event.url);
|
||||
window.scrollTo({top: 0});
|
||||
}
|
||||
window.scrollTo({top: 0});
|
||||
}
|
||||
if (fragment) {
|
||||
let i = 0;
|
||||
|
@ -52,10 +47,8 @@ export class SmoothScroll {
|
|||
clearInterval(this.interval);
|
||||
}
|
||||
}, 100);
|
||||
} else {
|
||||
if (!event.url.includes('/continent') && !event.url.includes('/country')) {
|
||||
window.scrollTo({top: 0, behavior: 'smooth'});
|
||||
}
|
||||
} else if(!this.whitelist.includes(this.getUrl(event.url))) {
|
||||
window.scrollTo({top: 0, behavior: 'smooth'});
|
||||
}
|
||||
this.lastRoute = this.getUrl(event.url);
|
||||
}
|
||||
|
@ -63,8 +56,10 @@ export class SmoothScroll {
|
|||
}
|
||||
}
|
||||
|
||||
private getUrl(url: string) {
|
||||
return url.split('?')[0].split('#')[0];
|
||||
private getUrl(url: string): string {
|
||||
let full = url.split('?')[0].split('#')[0];
|
||||
let route = this.whitelist.find(_ => full.includes(_));
|
||||
return (route)?(route):full;
|
||||
}
|
||||
|
||||
public clearSubscriptions() {
|
||||
|
@ -76,3 +71,4 @@ export class SmoothScroll {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue