mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
30 lines
653 B
TypeScript
30 lines
653 B
TypeScript
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[] = []
|
|
|
|
constructor(
|
|
private router: Router,
|
|
private location: Location
|
|
) {
|
|
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('/')
|
|
}
|
|
}
|
|
}
|
|
|