Skip to content

Commit 2d94378

Browse files
author
cleancodecraft
committed
feat(routes): redirect added and site favicon added
1 parent de49a64 commit 2d94378

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed
Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import { Component } from '@angular/core';
1+
import { Component, OnInit, OnDestroy, inject, Inject } from '@angular/core';
22
import { RouterOutlet } from '@angular/router';
3+
import { Subscription } from 'rxjs';
4+
import { BlogInfo } from './models/blog-info';
5+
import { BlogService } from './services/blog.service';
6+
import { ThemeService } from './services/theme.service';
7+
import { DOCUMENT } from '@angular/common';
38

49
@Component({
510
selector: 'app-root',
@@ -8,6 +13,42 @@ import { RouterOutlet } from '@angular/router';
813
templateUrl: './app.component.html',
914
styleUrl: './app.component.scss'
1015
})
11-
export class AppComponent {
16+
export class AppComponent implements OnInit, OnDestroy {
1217
title = 'angular-primeng-app';
18+
blogURL!: string;
19+
blogInfo!: BlogInfo;
20+
siteFavicon: any;
21+
themeService: ThemeService = inject(ThemeService);
22+
blogService: BlogService = inject(BlogService);
23+
private querySubscription?: Subscription;
24+
25+
constructor(@Inject(DOCUMENT) private document: Document) {}
26+
27+
ngOnInit(): void {
28+
this.blogURL = this.blogService.getBlogURL();
29+
this.siteFavicon = this.document.querySelector('link[rel="icon"]') as HTMLLinkElement;
30+
this.querySubscription = this.blogService
31+
.getBlogInfo(this.blogURL)
32+
.subscribe((data) => {
33+
this.blogInfo = data;
34+
if (this.blogInfo.isTeam && this.blogInfo.favicon) {
35+
this.siteFavicon.href = this.blogInfo.favicon;
36+
} else {
37+
this.siteFavicon.href = "favicon.ico";
38+
}
39+
if (!this.blogInfo.isTeam) {
40+
this.blogService.getAuthorInfo(this.blogURL).subscribe((data) => {
41+
if (data.profilePicture) {
42+
this.siteFavicon.href = data.profilePicture;
43+
} else {
44+
this.siteFavicon.href = "favicon.ico";
45+
}
46+
});
47+
}
48+
});
49+
}
50+
51+
ngOnDestroy(): void {
52+
this.querySubscription?.unsubscribe();
53+
}
1354
}

angular-primeng-app/src/app/app.routes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@ export const routes: Routes = [
2323
{
2424
path: 'post/:slug',
2525
component: PostDetailsComponent
26+
},
27+
{
28+
path: '**',
29+
redirectTo: ''
2630
}
2731
];

0 commit comments

Comments
 (0)