Angular 19 SSR: The 'detail/:id' route uses prerendering and includes parameters, but...

Discussão em 'Angular' iniciado por Menahem Gil, Março 31, 2025.

  1. Menahem Gil

    Menahem Gil Guest

    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: https://angular.dev/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

    Continue reading...

Compartilhe esta Página