|
| 1 | +import { NgModule, Inject } from '@angular/core'; |
| 2 | +import { RouterModule, PreloadAllModules } from '@angular/router'; |
| 3 | +import { CommonModule, APP_BASE_HREF } from '@angular/common'; |
| 4 | +import { HttpModule, Http } from '@angular/http'; |
| 5 | +import { HttpClientModule, HttpClient } from '@angular/common/http'; |
| 6 | +import { FormsModule } from '@angular/forms'; |
| 7 | +import { BrowserModule, BrowserTransferStateModule } from '@angular/platform-browser'; |
| 8 | +import { TransferHttpCacheModule } from '@nguniversal/common'; |
| 9 | + |
| 10 | +import { Ng2BootstrapModule } from 'ngx-bootstrap'; |
| 11 | + |
| 12 | +// i18n support |
| 13 | +import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; |
| 14 | +import { TranslateHttpLoader } from '@ngx-translate/http-loader'; |
| 15 | + |
| 16 | +import { AppComponent } from './app.component'; |
| 17 | +import { NavMenuComponent } from './components/navmenu/navmenu.component'; |
| 18 | +import { HomeComponent } from './containers/home/home.component'; |
| 19 | +import { UsersComponent } from './containers/users/users.component'; |
| 20 | +import { UserDetailComponent } from './components/user-detail/user-detail.component'; |
| 21 | +import { CounterComponent } from './containers/counter/counter.component'; |
| 22 | +import { NotFoundComponent } from './containers/not-found/not-found.component'; |
| 23 | +import { NgxBootstrapComponent } from './containers/ngx-bootstrap-demo/ngx-bootstrap.component'; |
| 24 | + |
| 25 | +import { LinkService } from './shared/link.service'; |
| 26 | +import { UserService } from './shared/user.service'; |
| 27 | +<<<<<<< HEAD |
| 28 | +import { ORIGIN_URL } from '@nguniversal/aspnetcore-engine/tokens'; |
| 29 | +======= |
| 30 | +import { ORIGIN_URL } from '@nguniversal/aspnetcore-engine'; |
| 31 | +>>>>>>> feat(Angular 5.0): update engine-etc for angular 5.0 & Domino (#437) |
| 32 | + |
| 33 | +export function createTranslateLoader(http: HttpClient, baseHref) { |
| 34 | + // Temporary Azure hack |
| 35 | + if (baseHref === null && typeof window !== 'undefined') { |
| 36 | + baseHref = window.location.origin; |
| 37 | + } |
| 38 | + // i18n files are in `wwwroot/assets/` |
| 39 | + return new TranslateHttpLoader(http, `${baseHref}/assets/i18n/`, '.json'); |
| 40 | +} |
| 41 | + |
| 42 | +@NgModule({ |
| 43 | + declarations: [ |
| 44 | + AppComponent, |
| 45 | + NavMenuComponent, |
| 46 | + CounterComponent, |
| 47 | + UsersComponent, |
| 48 | + UserDetailComponent, |
| 49 | + HomeComponent, |
| 50 | + NotFoundComponent, |
| 51 | + NgxBootstrapComponent |
| 52 | + ], |
| 53 | + imports: [ |
| 54 | + CommonModule, |
| 55 | + BrowserModule.withServerTransition({ |
| 56 | + appId: 'my-app-id' // make sure this matches with your Server NgModule |
| 57 | + }), |
| 58 | + HttpClientModule, |
| 59 | + TransferHttpCacheModule, |
| 60 | + BrowserTransferStateModule, |
| 61 | + |
| 62 | + |
| 63 | + FormsModule, |
| 64 | + Ng2BootstrapModule.forRoot(), // You could also split this up if you don't want the Entire Module imported |
| 65 | + |
| 66 | + // i18n support |
| 67 | + TranslateModule.forRoot({ |
| 68 | + loader: { |
| 69 | + provide: TranslateLoader, |
| 70 | + useFactory: (createTranslateLoader), |
| 71 | + deps: [HttpClient, [ORIGIN_URL]] |
| 72 | + } |
| 73 | + }), |
| 74 | + |
| 75 | + // App Routing |
| 76 | + RouterModule.forRoot([ |
| 77 | + { |
| 78 | + path: '', |
| 79 | + redirectTo: 'home', |
| 80 | + pathMatch: 'full' |
| 81 | + }, |
| 82 | + { |
| 83 | + path: 'home', component: HomeComponent, |
| 84 | + |
| 85 | + // *** SEO Magic *** |
| 86 | + // We're using "data" in our Routes to pass in our <title> <meta> <link> tag information |
| 87 | + // Note: This is only happening for ROOT level Routes, you'd have to add some additional logic if you wanted this for Child level routing |
| 88 | + // When you change Routes it will automatically append these to your document for you on the Server-side |
| 89 | + // - check out app.component.ts to see how it's doing this |
| 90 | + data: { |
| 91 | + title: 'Homepage', |
| 92 | + meta: [{ name: 'description', content: 'This is an example Description Meta tag!' }], |
| 93 | + links: [ |
| 94 | + { rel: 'canonical', href: 'http://blogs.example.com/blah/nice' }, |
| 95 | + { rel: 'alternate', hreflang: 'es', href: 'http://es.example.com/' } |
| 96 | + ] |
| 97 | + } |
| 98 | + }, |
| 99 | + { |
| 100 | + path: 'counter', component: CounterComponent, |
| 101 | + data: { |
| 102 | + title: 'Counter', |
| 103 | + meta: [{ name: 'description', content: 'This is an Counter page Description!' }], |
| 104 | + links: [ |
| 105 | + { rel: 'canonical', href: 'http://blogs.example.com/counter/something' }, |
| 106 | + { rel: 'alternate', hreflang: 'es', href: 'http://es.example.com/counter' } |
| 107 | + ] |
| 108 | + } |
| 109 | + }, |
| 110 | + { |
| 111 | + path: 'users', component: UsersComponent, |
| 112 | + data: { |
| 113 | + title: 'Users REST example', |
| 114 | + meta: [{ name: 'description', content: 'This is User REST API example page Description!' }], |
| 115 | + links: [ |
| 116 | + { rel: 'canonical', href: 'http://blogs.example.com/chat/something' }, |
| 117 | + { rel: 'alternate', hreflang: 'es', href: 'http://es.example.com/users' } |
| 118 | + ] |
| 119 | + } |
| 120 | + }, |
| 121 | + { |
| 122 | + path: 'ngx-bootstrap', component: NgxBootstrapComponent, |
| 123 | + data: { |
| 124 | + title: 'Ngx-bootstrap demo!!', |
| 125 | + meta: [{ name: 'description', content: 'This is an Demo Bootstrap page Description!' }], |
| 126 | + links: [ |
| 127 | + { rel: 'canonical', href: 'http://blogs.example.com/bootstrap/something' }, |
| 128 | + { rel: 'alternate', hreflang: 'es', href: 'http://es.example.com/bootstrap-demo' } |
| 129 | + ] |
| 130 | + } |
| 131 | + }, |
| 132 | + |
| 133 | + { path: 'lazy', loadChildren: './containers/lazy/lazy.module#LazyModule'}, |
| 134 | + |
| 135 | + { |
| 136 | + path: '**', component: NotFoundComponent, |
| 137 | + data: { |
| 138 | + title: '404 - Not found', |
| 139 | + meta: [{ name: 'description', content: '404 - Error' }], |
| 140 | + links: [ |
| 141 | + { rel: 'canonical', href: 'http://blogs.example.com/bootstrap/something' }, |
| 142 | + { rel: 'alternate', hreflang: 'es', href: 'http://es.example.com/bootstrap-demo' } |
| 143 | + ] |
| 144 | + } |
| 145 | + } |
| 146 | + ], { |
| 147 | + // Router options |
| 148 | + useHash: false, |
| 149 | + preloadingStrategy: PreloadAllModules, |
| 150 | + initialNavigation: 'enabled' |
| 151 | + }) |
| 152 | + ], |
| 153 | + providers: [ |
| 154 | + LinkService, |
| 155 | + UserService, |
| 156 | + TranslateModule |
| 157 | + ], |
| 158 | + bootstrap: [AppComponent] |
| 159 | +}) |
| 160 | +export class AppModuleShared { |
| 161 | +} |
0 commit comments