Skip to content

Commit c158256

Browse files
committed
Define server routes and rendering types.
1 parent 9bf8945 commit c158256

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

angular.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"budgets": [
5353
{
5454
"type": "initial",
55-
"maximumWarning": "500kB",
55+
"maximumWarning": "620kB",
5656
"maximumError": "1MB"
5757
},
5858
{

src/app/app.config.server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import { provideServerRendering } from '@angular/platform-server';
33
import { appConfig } from './app.config';
44
import { UniversalDeviceDetectorService } from './services/universal-device-detector.service';
55
import { DeviceDetectorService } from 'ngx-device-detector';
6+
import { provideServerRoutesConfig } from '@angular/ssr';
7+
import { serverRoutes } from './app.routes.server';
68

79
const serverConfig: ApplicationConfig = {
810
providers: [
911
provideServerRendering(),
12+
provideServerRoutesConfig(serverRoutes),
1013
{
1114
provide: DeviceDetectorService,
1215
useClass: UniversalDeviceDetectorService,

src/app/app.routes.server.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { RenderMode, ServerRoute } from '@angular/ssr';
2+
3+
export const serverRoutes: ServerRoute[] = [
4+
{
5+
path: '', // This page is static, so we prerender it (SSG)
6+
renderMode: RenderMode.Prerender,
7+
},
8+
{
9+
path: 'pokedex-bad', // This renders the "/pokedex-bad" route on the server (SSR)
10+
renderMode: RenderMode.Server,
11+
},
12+
{
13+
path: 'pokedex-optimized', // This renders the "/pokedex-optimized" route on the server (SSR)
14+
renderMode: RenderMode.Server,
15+
},
16+
{
17+
path: '**', // All other routes - like the individual pokemon pages - will be rendered on the client (CSR)
18+
renderMode: RenderMode.Client,
19+
},
20+
];

src/app/app.routes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Routes } from '@angular/router';
22

33
export const routes: Routes = [
44
{
5-
path: 'pokedex',
5+
path: '',
66
loadComponent: () =>
77
import('./components/intro/intro.component').then(m => m.IntroComponent),
88
},
@@ -34,5 +34,5 @@ export const routes: Routes = [
3434
m => m.DetailsOptimizedPageComponent
3535
),
3636
},
37-
{ path: '', redirectTo: '/pokedex', pathMatch: 'full' },
37+
{ path: '**', redirectTo: '/', pathMatch: 'full' },
3838
];

0 commit comments

Comments
 (0)