angularserver-side-renderingangular9angular-universal

Angular Universal page loads twice on SSR


I don't have any higher level NgIf on my main code ( app.component.html) that would cause a reload. I'm using transferstate so requests won't be called after SSR sets the answers of the public urls. I'm using isPlatFormBrowser for JS parts. I checked SSR on local and its not causing any errors.

But some of my pages are getting reloaded after ssr and one of them is just a static html css page without any logic in the ts file.

any idea on how to fix it?


Solution

  • I found the problem and i decided to share it with the future viewers. this problem doesn't happen to pages which have routes to them directly from app-routing and it just happens to pages that have routes with RouterModule.forChild and you can fix it by adding

    {
       initialNavigation:'enabled'
    }
    

    to

    [RouterModule.forRoot([ROUTES],{
        initialNavigation:'enabled'
    })]