Let's say we have this Post component:
@Component({
template: `
<div
*ngIf="post$ | async as post"
[innerHTML]="post.content">
</div>
`,
})
export class Post implements OnInit {
post$!: Observable<Post>;
constructor(private http: HttpClient, private route: ActivatedRoute) {}
ngOnInit(): void {
this.post$ = this.route.paramMap.pipe(
switchMap((params) => {
const slug = params.get('slug') ;
return this.http.get<Post>(`${env.apiUrl}/posts/${slug}`);
})
);
}
}
When we pre-render posts pages:
ng run myapp:prerender --routes-file routes.txt
Their data are fetched and the HTML is generated successfully. But when we launch the generated static content, they still RE-fetch the data.
Is it possible to prevent that RE-fetch ? or it is not recommended ?