Angular universal. Dynamic routes are not rendered server-side

1.2k Views Asked by At

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

1

There are 1 best solutions below

5
Alejandro Barone On BEST ANSWER

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