mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 13:55:51 +00:00
fix go back
This commit is contained in:
@@ -9,7 +9,6 @@ import { Location } from '@angular/common'
|
|||||||
export class RouteService {
|
export class RouteService {
|
||||||
|
|
||||||
history: any = [];
|
history: any = [];
|
||||||
isGoBack = false;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
@@ -26,7 +25,7 @@ export class RouteService {
|
|||||||
|
|
||||||
if(event.url != lastRoute) {
|
if(event.url != lastRoute) {
|
||||||
this.history.push(event.url)
|
this.history.push(event.url)
|
||||||
this.LocalstoreService.set('history', this.history)
|
this.reduceHistory()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -41,23 +40,50 @@ export class RouteService {
|
|||||||
goBack(url = null) {
|
goBack(url = null) {
|
||||||
if(this.history.length >= 2) {
|
if(this.history.length >= 2) {
|
||||||
this.history.pop();
|
this.history.pop();
|
||||||
const goTo = this.history.pop();
|
const url = this.history.pop();
|
||||||
|
|
||||||
this.Location.back()
|
this.goTo(url)
|
||||||
|
|
||||||
} else if(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) {
|
if(this.history.length >= 15) {
|
||||||
this.history = this.history.slice(5, this.history.length)
|
this.history = this.history.slice(5, this.history.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.LocalstoreService.set('history', this.history)
|
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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user