mirror of https://github.com/abpframework/abp.git
committed by
GitHub
8 changed files with 63 additions and 5 deletions
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 1.4 KiB |
@ -0,0 +1,44 @@ |
|||||
|
import { Injectable, effect, inject } from '@angular/core'; |
||||
|
import { toSignal } from '@angular/core/rxjs-interop'; |
||||
|
import { TitleStrategy, RouterStateSnapshot } from '@angular/router'; |
||||
|
import { Title } from '@angular/platform-browser'; |
||||
|
import { ConfigStateService } from './config-state.service'; |
||||
|
import { LocalizationService } from './localization.service'; |
||||
|
|
||||
|
@Injectable({ |
||||
|
providedIn: 'root', |
||||
|
}) |
||||
|
export class AbpTitleStrategy extends TitleStrategy { |
||||
|
protected readonly title = inject(Title); |
||||
|
protected readonly configState = inject(ConfigStateService); |
||||
|
protected readonly localizationService = inject(LocalizationService); |
||||
|
protected routerState: RouterStateSnapshot; |
||||
|
|
||||
|
projectName = toSignal(this.configState.getDeep$('localization.defaultResourceName'), { |
||||
|
initialValue: 'MyProjectName', |
||||
|
}); |
||||
|
langugageChange = toSignal(this.localizationService.languageChange$); |
||||
|
|
||||
|
constructor() { |
||||
|
super(); |
||||
|
effect(() => { |
||||
|
if (this.langugageChange()) { |
||||
|
this.updateTitle(this.routerState); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
override updateTitle(routerState: RouterStateSnapshot) { |
||||
|
let title = this.buildTitle(routerState); |
||||
|
|
||||
|
if (!title) { |
||||
|
this.title.setTitle(this.projectName()); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
this.routerState = routerState; |
||||
|
|
||||
|
const localizedTitle = this.localizationService.instant({ key: title, defaultValue: title }); |
||||
|
this.title.setTitle(`${localizedTitle} | ${this.projectName()}`); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue