teste/route

This commit is contained in:
Peter Maquiran
2022-02-16 15:52:59 +01:00
parent 1efea5bdf7
commit 439332a52e
35 changed files with 309 additions and 286 deletions
+19 -8
View File
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { NavigationEnd, Router, NavigationStart } from '@angular/router';
import { NavigationEnd, Router, NavigationStart, NavigationExtras } from '@angular/router';
import { LocalstoreService } from '../store/localstore.service';
import { Location } from '@angular/common'
@Injectable({
providedIn: 'root'
@@ -12,7 +13,12 @@ export class RouteService {
constructor(
private router: Router,
private LocalstoreService: LocalstoreService,
private Location: Location
) {
this.history = this.LocalstoreService.get('history', [])
this.router.events.forEach((event) => {
if (event instanceof NavigationEnd) {
@@ -20,6 +26,7 @@ export class RouteService {
if(event.url != lastRoute) {
this.history.push(event.url)
this.LocalstoreService.set('history', this.history)
}
}
@@ -30,19 +37,23 @@ export class RouteService {
}
/**
* @param url [string] incase no history to go back
* @param option [Object] some options to the url
*/
goBack(url = null, option: object = {}) {
* @param url [string] incase no history to go back */
goBack(url = null) {
if(this.history.length >= 2) {
this.history.pop();
const goTo = this.history.pop();
this.isGoBack = true;
this.router.navigate([goTo]);
this.Location.back()
} else if(url) {
this.goTo({url})
}
if(this.history.length >= 15) {
this.history = this.history.slice(5, this.history.length)
}
this.LocalstoreService.set('history', this.history)
}
goTo({url}) {