From 34ce0e4fde3df4a628873e3f34411b2888e526d3 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Wed, 16 Feb 2022 16:21:08 +0100 Subject: [PATCH] fix go back --- src/app/services/route.service.ts | 42 +++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/app/services/route.service.ts b/src/app/services/route.service.ts index 54bcf24d3..16eef1b09 100644 --- a/src/app/services/route.service.ts +++ b/src/app/services/route.service.ts @@ -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 + } }