最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论