angularroutesserver-side-renderinguniversal

Angular universal. Dynamic routes are not rendered server-side


I have problem with Server-side rendering dynamic routes with angular universal.

for example:

{ path: 'room/:slug', Component: RoomDetailsComponent }

will not be server side rendered.

{ path: 'room/first-room', Component: RoomDetailsComponent }

will be server side rendered.

I found some solutions for this, like fetching the routes from back-end service. I think there should be better, less hackier way of doing this


Solution

  • Maybe you are missing a property int the RouterModule declaration, because that should work as expected.

    Here I create a stackblitz that you can download and test it out with npm run dev:ssr (it has that same example)

    As you can see in the picture, the dynamic parameter is rendered on server side (as its returned in the doc response <body>) param rendered in server