I try to build Angular 19 SSR using ng build --configuration production --aot
but get the following error:
[ERROR] The 'detail/:id' route uses prerendering and includes parameters, but 'getPrerenderParams' is missing. Please define 'getPrerenderParams' function for this route in your server routing configuration or specify a different 'renderMode'.
When I just serve the app locally I don't get this error, only when I try to build.
This is my routes array:
export const routes: Routes = [{
path: '',
component: HomePageComponent,
title: '',
}, {
path: 'detail/:id',
component: detailsComponent
}, {
path: 'about',
component: AboutComponent,
title: 'About us'
... etc.
];
Now, I saw this in the documentation but not sure where to place the file and how to relate it to the entire app: /guide/hybrid-rendering
// app.routes.server.ts
import { RenderMode, ServerRoute } from '@angular/ssr';
export const serverRoutes: ServerRoute[] = [
{
path: 'post/:id',
renderMode: RenderMode.Prerender,
async getPrerenderParams() {
const dataService = inject(PostService);
const ids = await dataService.getIds(); // Assuming this returns ['1', '2', '3']
return ids.map(id => ({ id })); // Transforms IDs into an array of objects for prerendering
// This will prerender the paths: `/post/1`, `/post/2` and `/post/3`
},
},
];
Bottom line - how can I build my app ?
Thanks