Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add title changing to router #72

Merged
merged 2 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions client/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,49 @@ const routes: Routes = [
},
{
path: 'login',
data: { title: 'Login' },
loadChildren: () =>
import('./pages/login/login.module').then((m) => m.LoginPageModule),
},
{
path: 'explore',
canActivate: [AuthGuard],
data: { title: 'Explore' },
loadChildren: () =>
import('./pages/explore/explore.module').then((m) => m.ExplorePageModule),
},
{
path: 'travel',
canActivate: [AuthGuard],
data: { title: 'Travel' },
loadChildren: () =>
import('./pages/travel/travel.module').then((m) => m.TravelPageModule),
},
{
path: 'town',
canActivate: [AuthGuard],
data: { title: 'Town' },
loadChildren: () =>
import('./pages/town/town.module').then((m) => m.TownPageModule),
},
{
path: 'me',
canActivate: [AuthGuard],
data: { title: 'My Profile' },
loadChildren: () =>
import('./pages/me/me.module').then((m) => m.MePageModule),
},
{
path: 'options',
canActivate: [AuthGuard],
data: { title: 'Options' },
loadChildren: () =>
import('./pages/options/options.module').then((m) => m.OptionsPageModule),
},
{
path: 'inventory',
canActivate: [AuthGuard],
data: { title: 'Inventory' },
loadChildren: () =>
import('./pages/inventory/inventory.module').then(
(m) => m.InventoryPageModule,
Expand All @@ -55,6 +62,7 @@ const routes: Routes = [
{
path: 'equipment',
canActivate: [AuthGuard],
data: { title: 'Equipment' },
loadChildren: () =>
import('./pages/equipment/equipment.module').then(
(m) => m.EquipmentPageModule,
Expand All @@ -63,6 +71,7 @@ const routes: Routes = [
{
path: 'collections',
canActivate: [AuthGuard],
data: { title: 'Collections' },
loadChildren: () =>
import('./pages/collections/collections.module').then(
(m) => m.CollectionsPageModule,
Expand Down
34 changes: 33 additions & 1 deletion client/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Component } from '@angular/core';
import { ActivatedRoute, Router, NavigationEnd } from '@angular/router';
import { Title } from '@angular/platform-browser';
import { filter, map } from 'rxjs/operators';

interface IMenuItem {
title: string;
Expand Down Expand Up @@ -48,5 +51,34 @@ export class AppComponent {
},
];

constructor() {}
constructor(
private router: Router,
private activatedRoute: ActivatedRoute,
private titleService: Title,
) {
this.router.events
.pipe(
filter((event) => event instanceof NavigationEnd),
map(() => {
let child = this.activatedRoute.firstChild;
while (child) {
if (child.firstChild) {
child = child.firstChild;
} else if (child.snapshot.data && child.snapshot.data['title']) {
return child.snapshot.data['title'];
} else {
return null;
}
}
return null;
}),
)
.subscribe((data: any) => {
if (data) {
this.titleService.setTitle(`${data} | AtEoAT`);
} else {
this.titleService.setTitle('After the End of All Things');
}
});
}
}
92 changes: 58 additions & 34 deletions client/src/index.html
Original file line number Diff line number Diff line change
@@ -1,37 +1,61 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8"/>
<title>After the End of the World</title>

<base href="/"/>

<meta name="color-scheme" content="light dark"/>
<meta name="viewport" content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="format-detection" content="telephone=no"/>
<meta name="msapplication-tap-highlight" content="no"/>

<link rel="apple-touch-icon" sizes="180x180" href="assets/favicon/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="assets/favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="assets/favicon/favicon-16x16.png">
<link rel="mask-icon" href="assets/favicon/safari-pinned-tab.svg" color="#b35cfd">
<link rel="shortcut icon" href="assets/favicon/favicon.ico">
<meta name="msapplication-TileColor" content="#b35cfd">
<meta name="msapplication-config" content="assets/favicon/browserconfig.xml">
<meta name="theme-color" content="#b35cfd">

<link rel="manifest" href="assets/favicon/manifest.json">

<!-- add to homescreen for ios -->
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
<meta name="theme-color" content="#1976d2">
</head>

<body>
<app-root></app-root>
<noscript>Please enable JavaScript to continue using this application.</noscript>
</body>

<head>
<meta charset="utf-8" />
<title>After the End of All Things</title>

<base href="/" />

<meta name="color-scheme" content="light dark" />
<meta
name="viewport"
content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />

<link
rel="apple-touch-icon"
sizes="180x180"
href="assets/favicon/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="assets/favicon/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="assets/favicon/favicon-16x16.png"
/>
<link
rel="mask-icon"
href="assets/favicon/safari-pinned-tab.svg"
color="#b35cfd"
/>
<link rel="shortcut icon" href="assets/favicon/favicon.ico" />
<meta name="msapplication-TileColor" content="#b35cfd" />
<meta
name="msapplication-config"
content="assets/favicon/browserconfig.xml"
/>
<meta name="theme-color" content="#b35cfd" />

<link rel="manifest" href="assets/favicon/manifest.json" />

<!-- add to homescreen for ios -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="theme-color" content="#1976d2" />
</head>

<body>
<app-root></app-root>
<noscript>
Please enable JavaScript to continue using this application.
</noscript>
</body>
</html>