Skip to content

Commit c18466c

Browse files
authored
Merge pull request #39 from Stivin/fix_meta
Перенес meta в директорию shared
2 parents c0d119b + 6338474 commit c18466c

File tree

9 files changed

+75
-50
lines changed

9 files changed

+75
-50
lines changed

src/app/app.module.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { BrowserModule } from '@angular/platform-browser';
66
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
77
// libs
88
import { CookieService } from 'ngx-cookie-service';
9-
import { MetaLoader, MetaModule, MetaSettings, MetaStaticLoader, PageTitlePositioning, } from '@ngx-meta/core';
109
import { PrebootModule } from 'preboot';
1110
// shared
1211
import { TransferHttpModule } from '../modules/transfer-http/transfer-http.module';
@@ -15,29 +14,7 @@ import { SharedModule } from '@shared/shared.module';
1514
import { AppRoutes } from './app.routing';
1615
import { AppComponent } from './app.component';
1716

18-
export function metaFactory(): MetaLoader {
19-
const setting: MetaSettings = {
20-
callback: (key: string) => key,
21-
pageTitlePositioning: PageTitlePositioning.PrependPageTitle,
22-
pageTitleSeparator: ' | ',
23-
applicationName: 'App Universal',
24-
// applicationUrl: 'https://gorniv.com/',
25-
defaults: {
26-
title: 'default page title',
27-
description: 'default description',
28-
'og:site_name': 'App site Universal',
29-
'og:type': 'website',
30-
'og:locale': 'ru_RU',
31-
'og:locale:alternate': 'en_GB'
32-
}
33-
};
34-
return new MetaStaticLoader(setting);
35-
}
36-
3717
@NgModule({
38-
declarations: [
39-
AppComponent,
40-
],
4118
imports: [
4219
BrowserModule.withServerTransition({ appId: 'my-app' }),
4320
PrebootModule.withConfig({ appRoot: 'app-root' }),
@@ -47,12 +24,8 @@ export function metaFactory(): MetaLoader {
4724
TransferHttpModule,
4825
BrowserAnimationsModule,
4926
SharedModule.forRoot(),
50-
MetaModule.forRoot({
51-
provide: MetaLoader,
52-
useFactory: metaFactory,
53-
deps: []
54-
}),
5527
],
28+
declarations: [AppComponent],
5629
providers: [CookieService],
5730
bootstrap: [AppComponent]
5831
})

src/app/app.routing.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,10 @@ import { WrapperComponent } from '@shared/layouts/wrapper/wrapper.component';
66
const routes: Routes = [
77
{ path: '', redirectTo: 'home', pathMatch: 'full' },
88
{
9-
path: '', component: WrapperComponent, children: [
10-
{
11-
path: 'home', loadChildren: './home/home.module#HomeModule',
12-
data: {
13-
// for override default meta
14-
meta: {
15-
title: 'home title',
16-
override: true,
17-
description: 'home description'
18-
}
19-
},
20-
// need for default meta
21-
canActivateChild: [MetaGuard],
22-
},
23-
// without meta
9+
path: '', component: WrapperComponent, canActivateChild: [MetaGuard], children: [
10+
{ path: 'home', loadChildren: './home/home.module#HomeModule' },
2411
{ path: 'mock', loadChildren: './mock-server-browser/mock-server-browser.module#MockServerBrowserModule' },
25-
// with meta
26-
{ path: 'back', loadChildren: './transfer-back/transfer-back.module#TransferBackModule', canActivateChild: [MetaGuard] },
27-
// 404
12+
{ path: 'back', loadChildren: './transfer-back/transfer-back.module#TransferBackModule' },
2813
{ path: '**', loadChildren: './not-found/not-found.module#NotFoundModule' },
2914
]
3015
}

src/app/home/home.routing.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ import { HomeComponent } from './home.component';
22
import { Routes, RouterModule } from '@angular/router';
33

44
const routes: Routes = [
5-
{ path: '', component: HomeComponent },
5+
{
6+
path: '', component: HomeComponent,
7+
data: {
8+
meta: {
9+
title: 'Home title',
10+
override: true,
11+
description: 'Home description'
12+
}
13+
},
14+
},
615
];
716

817
export const HomeRoutes = RouterModule.forChild(routes);

src/app/mock-server-browser/mock-server-browser.routing.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ import { Routes, RouterModule } from '@angular/router';
22
import { MockServerBrowserComponent } from './mock-server-browser.component';
33

44
const routes: Routes = [
5-
{ path: '', component: MockServerBrowserComponent },
5+
{
6+
path: '', component: MockServerBrowserComponent,
7+
data: {
8+
meta: {
9+
title: 'Mock title',
10+
description: 'Mock description'
11+
}
12+
},
13+
},
614
];
715

816
export const MockServerBrowserRoutes = RouterModule.forChild(routes);

src/app/not-found/not-found.routing.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ import { NotFoundComponent } from './not-found.component';
22
import { Routes, RouterModule } from '@angular/router';
33

44
const routes: Routes = [
5-
{ path: '' , component: NotFoundComponent},
5+
{
6+
path: '', component: NotFoundComponent,
7+
data: {
8+
meta: {
9+
title: 'Not Found',
10+
description: 'Page not found'
11+
}
12+
},
13+
},
614
];
715

816
export const NotFoundRoutes = RouterModule.forChild(routes);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { SharedMetaModule } from './shared-meta.module';
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { NgModule } from '@angular/core';
2+
import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core';
3+
4+
export function metaFactory(): MetaLoader {
5+
return new MetaStaticLoader({
6+
callback: (key: string): string => key,
7+
pageTitlePositioning: PageTitlePositioning.PrependPageTitle,
8+
pageTitleSeparator: ' | ',
9+
applicationName: 'App Universal',
10+
defaults: {
11+
title: 'Default page title',
12+
description: 'Default description',
13+
'og:site_name': 'App site Universal',
14+
'og:type': 'website',
15+
'og:locale': 'ru_RU',
16+
'og:locale:alternate': 'en_GB'
17+
}
18+
});
19+
}
20+
21+
@NgModule({
22+
imports: [
23+
MetaModule.forRoot({
24+
provide: MetaLoader,
25+
useFactory: metaFactory,
26+
deps: []
27+
})
28+
]
29+
})
30+
export class SharedMetaModule {
31+
}

src/app/shared/shared.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { ModuleWithProviders, NgModule } from '@angular/core';
22

33
import { LayoutsModule } from './layouts/layouts.module';
4+
import { SharedMetaModule } from './shared-meta';
45

56
@NgModule({
67
exports: [
78
LayoutsModule,
9+
SharedMetaModule
810
],
911
providers: []
1012
})

src/app/transfer-back/transfer-back.routing.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ import { TransferBackComponent } from './transfer-back.component';
22
import { Routes, RouterModule } from '@angular/router';
33

44
const routes: Routes = [
5-
{ path: '' , component: TransferBackComponent},
5+
{
6+
path: '', component: TransferBackComponent,
7+
data: {
8+
meta: {
9+
title: 'Back title',
10+
description: 'Back description'
11+
}
12+
},
13+
},
614
];
715

816
export const TransferBackRoutes = RouterModule.forChild(routes);

0 commit comments

Comments
 (0)