examples/angular/ssr
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Angular Query SSR Example#
A list of posts that is rendered on the server and hydrated in the browser without fetching again.
Built with Angular SSR.
How it works#
src/app/services/posts.service.tsis an@InjectablePostsServicethat returns in-memory posts as an observable, so the example needs no API.src/app/components/posts.component.tsreads the posts withinjectQueryandlastValueFrom. The query runs during server rendering, and the server waits for it before sending the HTML.src/app/query-client.tsexports thecreateQueryClientfactory. It runs in an injection context, so it usesPLATFORM_IDto turn offretryon the server.src/app/app.config.tspasses the factory toprovideTanStackQuery, which transfers the query cache from the server to the browser, and addsprovideClientHydrationandwithDevtools().src/app/app.config.server.ts,src/main.server.tsandsrc/server.tsare the Angular CLI server files.src/app/app.routes.server.tsrenders every route withRenderMode.Server.
To run this example:
npm installnpm start
To run the production server, run npm run build and then npm run serve:ssr.