2021-07-27 22:34:47 +01:00
|
|
|
import { Injectable } from '@angular/core'
|
|
|
|
|
import { Location } from '@angular/common'
|
|
|
|
|
import { Router, NavigationEnd } from '@angular/router'
|
|
|
|
|
|
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
|
|
|
export class NavigationService {
|
|
|
|
|
private history: string[] = []
|
|
|
|
|
|
2022-01-06 14:47:22 +01:00
|
|
|
constructor(
|
|
|
|
|
private router: Router,
|
|
|
|
|
private location: Location
|
|
|
|
|
) {
|
2021-07-27 22:34:47 +01:00
|
|
|
this.router.events.subscribe((event) => {
|
|
|
|
|
if (event instanceof NavigationEnd) {
|
|
|
|
|
this.history.push(event.urlAfterRedirects)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
back(): void {
|
|
|
|
|
this.history.pop()
|
|
|
|
|
if (this.history.length > 0) {
|
|
|
|
|
this.location.back()
|
|
|
|
|
} else {
|
|
|
|
|
this.router.navigateByUrl('/')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|