fix go back

This commit is contained in:
Peter Maquiran
2022-02-16 16:21:08 +01:00
parent 4c0412220d
commit 34ce0e4fde
+34 -8
View File
@@ -9,7 +9,6 @@ import { Location } from '@angular/common'
export class RouteService {
history: any = [];
isGoBack = false;
constructor(
private router: Router,
@@ -26,7 +25,7 @@ export class RouteService {
if(event.url != lastRoute) {
this.history.push(event.url)
this.LocalstoreService.set('history', this.history)
this.reduceHistory()
}
}
@@ -41,23 +40,50 @@ export class RouteService {
goBack(url = null) {
if(this.history.length >= 2) {
this.history.pop();
const goTo = this.history.pop();
const url = this.history.pop();
this.Location.back()
this.goTo(url)
} else if(url) {
this.goTo({url})
this.goTo(url)
}
this.reduceHistory()
}
goTo(url) {
let navigationExtras: NavigationExtras = {
queryParams: this.queryParams(url)
}
const urlObject = new URL('http://localhost:8100'+url);
this.router.navigate([urlObject.pathname], navigationExtras);
}
reduceHistory() {
if(this.history.length >= 15) {
this.history = this.history.slice(5, this.history.length)
}
this.LocalstoreService.set('history', this.history)
}
goTo({url}) {
this.router.navigate([url]);
queryParams(url) {
const urlObject = new URL('http://localhost:8100'+url);
const paramsString = urlObject.search;
let searchParams: any = new URLSearchParams(paramsString);
let params = {}
for (let [key, value] of searchParams) {
params[key] = value
}
console.log('params', params)
return params
}
}