2018-06-10 04:40:53 +02:00
|
|
|
import { Injectable } from "@angular/core";
|
2018-07-06 04:37:35 +02:00
|
|
|
import { Title } from "@angular/platform-browser";
|
2018-06-10 04:40:53 +02:00
|
|
|
import { ActivatedRoute, NavigationEnd, Router } from "@angular/router";
|
2022-04-25 15:41:44 +02:00
|
|
|
import { filter } from "rxjs";
|
2018-06-10 04:40:53 +02:00
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
2018-07-06 04:37:35 +02:00
|
|
|
|
2018-06-10 04:40:53 +02:00
|
|
|
@Injectable()
|
|
|
|
export class RouterService {
|
|
|
|
private previousUrl: string = undefined;
|
|
|
|
private currentUrl: string = undefined;
|
|
|
|
|
2018-07-06 04:37:35 +02:00
|
|
|
constructor(
|
|
|
|
private router: Router,
|
|
|
|
private activatedRoute: ActivatedRoute,
|
2019-02-22 19:17:10 +01:00
|
|
|
private titleService: Title,
|
|
|
|
i18nService: I18nService
|
|
|
|
) {
|
2018-06-10 04:40:53 +02:00
|
|
|
this.currentUrl = this.router.url;
|
2022-04-25 15:41:44 +02:00
|
|
|
|
|
|
|
router.events
|
|
|
|
.pipe(filter((e) => e instanceof NavigationEnd))
|
|
|
|
.subscribe((event: NavigationEnd) => {
|
2018-06-10 04:40:53 +02:00
|
|
|
this.currentUrl = event.url;
|
2018-07-06 04:37:35 +02:00
|
|
|
|
|
|
|
let title = i18nService.t("pageTitle", "Bitwarden");
|
|
|
|
let child = this.activatedRoute.firstChild;
|
2022-04-25 15:41:44 +02:00
|
|
|
while (child.firstChild) {
|
|
|
|
child = child.firstChild;
|
2018-07-06 04:37:35 +02:00
|
|
|
}
|
|
|
|
|
2022-04-25 15:41:44 +02:00
|
|
|
const titleId: string = child?.snapshot?.data?.titleId;
|
|
|
|
const rawTitle: string = child?.snapshot?.data?.title;
|
|
|
|
const updateUrl = !child?.snapshot?.data?.doNotSaveUrl ?? true;
|
|
|
|
|
2018-07-06 04:37:35 +02:00
|
|
|
if (titleId != null || rawTitle != null) {
|
|
|
|
const newTitle = rawTitle != null ? rawTitle : i18nService.t(titleId);
|
|
|
|
if (newTitle != null && newTitle !== "") {
|
|
|
|
title = newTitle + " | " + title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.titleService.setTitle(title);
|
2022-04-25 15:41:44 +02:00
|
|
|
if (updateUrl) {
|
|
|
|
this.setPreviousUrl(this.currentUrl);
|
|
|
|
}
|
|
|
|
});
|
2018-06-10 04:40:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getPreviousUrl() {
|
|
|
|
return this.previousUrl;
|
|
|
|
}
|
2019-02-22 19:17:10 +01:00
|
|
|
|
|
|
|
setPreviousUrl(url: string) {
|
|
|
|
this.previousUrl = url;
|
|
|
|
}
|
2018-06-10 04:40:53 +02:00
|
|
|
}
|