Manuel
Manuel

Reputation: 9522

Angular ng build prerendered routes like angular universal for static serving (with open graph og tags)

Is it possible to build an angular app (angular 2/3/4/5) for production (with AoT) with several prerendered routes? I'm thinking of something similar to angular universal just during the build process for predefined routes.

For example:

./dist/index.html << this is default!
// Additional build prerendered index.html files for specified routes
./dist/routeA/index.html
./dist/routeB/index.html
./dist/routeC/customRouteParam/index.html

Why static prerendering of Angular?

Serverside Rendering with Angular Universal

I do know serverside prerendering is possible with angular universal however I'd like to avoid this extra complexity and rather host fully static. For anyone who is interested in angular universal serverside rendering the following resources may be useful:

Upvotes: 0

Views: 836

Answers (1)

David
David

Reputation: 34445

You can do prerendering with universal and then just serve the html files statically

The starter kit has a sample file, prerender.ts, showing how it's done. https://github.com/angular/universal-starter.

You just need to provide a list of known routes to prerender, then server side rendering is performed and the resulting html is saved to disk.

I used this approach for a website where content only changes every few months and it's quite fast

Upvotes: 3

Related Questions