mirror of
https://github.com/bitwarden/browser.git
synced 2024-10-10 06:08:34 +02:00
b12d0387f6
* Add jslib as a dependency * Cleanup tsconfig, webpack, add jslib-angular to package.json * Update all import paths * Add back @types/node. * Lint * Remove dummy module * Remove merge conflict * Group imports * Bump jslib
63 lines
2.2 KiB
TypeScript
63 lines
2.2 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { Title } from '@angular/platform-browser';
|
|
import {
|
|
ActivatedRoute,
|
|
NavigationEnd,
|
|
Router,
|
|
} from '@angular/router';
|
|
|
|
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
|
|
|
@Injectable()
|
|
export class RouterService {
|
|
private previousUrl: string = undefined;
|
|
private currentUrl: string = undefined;
|
|
|
|
constructor(private router: Router, private activatedRoute: ActivatedRoute,
|
|
private titleService: Title, i18nService: I18nService) {
|
|
this.currentUrl = this.router.url;
|
|
router.events.subscribe(event => {
|
|
if (event instanceof NavigationEnd) {
|
|
this.previousUrl = this.currentUrl;
|
|
this.currentUrl = event.url;
|
|
|
|
let title = i18nService.t('pageTitle', 'Bitwarden');
|
|
let titleId: string = null;
|
|
let rawTitle: string = null;
|
|
let child = this.activatedRoute.firstChild;
|
|
while (child != null) {
|
|
if (child.firstChild != null) {
|
|
child = child.firstChild;
|
|
} else if (child.snapshot.data != null && child.snapshot.data.title != null) {
|
|
rawTitle = child.snapshot.data.title;
|
|
break;
|
|
} else if (child.snapshot.data != null && child.snapshot.data.titleId != null) {
|
|
titleId = child.snapshot.data.titleId;
|
|
break;
|
|
} else {
|
|
titleId = null;
|
|
rawTitle = null;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (titleId != null || rawTitle != null) {
|
|
const newTitle = rawTitle != null ? rawTitle : i18nService.t(titleId);
|
|
if (newTitle != null && newTitle !== '') {
|
|
title = (newTitle + ' | ' + title);
|
|
}
|
|
}
|
|
this.titleService.setTitle(title);
|
|
}
|
|
});
|
|
}
|
|
|
|
getPreviousUrl() {
|
|
return this.previousUrl;
|
|
}
|
|
|
|
setPreviousUrl(url: string) {
|
|
this.previousUrl = url;
|
|
}
|
|
}
|