1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-09 05:57:40 +02:00
bitwarden-browser/apps/web/src/app/core/router.service.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
1.7 KiB
TypeScript
Raw Normal View History

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";
import { filter } from "rxjs";
2018-06-10 04:40:53 +02:00
import { I18nService } from "@bitwarden/common/platform/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;
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("bitWebVault");
if (this.currentUrl.includes("/sm/")) {
title = i18nService.t("bitSecretsManager");
}
2018-07-06 04:37:35 +02:00
let child = this.activatedRoute.firstChild;
while (child.firstChild) {
child = child.firstChild;
2018-07-06 04:37:35 +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);
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
}