问题描述
我的主代码( app.component.html )上没有任何更高级别的 NgIf 会导致重新加载我正在使用 transferstate 以便在 SSR 设置公共网址的答案后不会调用请求.我正在为 JS 部件使用 isPlatFormBrowser.我在本地检查了 SSR 并没有导致任何错误.
I dont have any higher level NgIf on my main code ( app.component.html ) that would cause a reloadI'm using transferstate so requests wont 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 error.
但是我的一些页面在 ssr 后重新加载,其中一个页面只是一个静态 html css 页面,ts 文件中没有任何功能.
But some of my pages are getting reloaded after ssr and one of them is just a static html css page without any functionality on the ts file.
对修复它有什么想法吗?
any idea about fixing it ?
推荐答案
我发现了这个问题,并决定与未来的观众分享.这个问题不会发生在直接从应用程序路由到它们的路由的页面上,它只会发生在具有 RouterModule.forChild 路由的页面上,您可以通过将 {initialNavigation:'enabled'} 添加到 [RouterModule.forRoot([ROUTES],{initialNavigation:'enabled'})]
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'})]
这篇关于Angular Universal 页面在 SSR 上加载两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!