mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
teste/route
This commit is contained in:
@@ -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}) {
|
||||
|
||||
Reference in New Issue
Block a user