Convert an existing non-SSR (Client-Side Rendering) Angular application to an SSR application
To convert non-SSR to SSR application in Angular, use the built-in Angular CLI command.
ng add @angular/ssr
This command automates the setup process, installing necessary packages, adding the necessary files and configurations for server-side rendering.
Note:
- Browser-only APIs: If your application uses browser-specific APIs (like
window,document,localStorage) outside of Angular lifecycle hooks (where they are safe), these will cause errors during the server-side rendering process. You may need to refactor this code or use platform-agnostic approaches. - Third-party libraries: Some third-party libraries might not be compatible with SSR. Check their documentation for specific instructions or alternatives.