AngularUniversal无限加载错误
创始人
2024-10-29 21:01:26
0
  1. 在 Angular Universal 的服务器渲染配置中添加一个选项 "initialNavigation" 并将其值设置为 false。如下所示:

    export const appRoutes: Routes = [ { path: '', component: HomeComponent, pathMatch: 'full' }, { path: 'about', component: AboutComponent }, { path: '**', component: NotFoundComponent } ];

    export const appRoutingProviders: any[] = [];

    export const appRouting: ModuleWithProviders = RouterModule.forRoot(appRoutes, { initialNavigation: false });

  2. 在你的组件中添加一些代码以检测服务器和浏览器。如下所示:

    import { isPlatformBrowser } from '@angular/common'; import { Component, Inject, PLATFORM_ID } from '@angular/core';

    @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'app';

    constructor(@Inject(PLATFORM_ID) private platformId: Object) { if (isPlatformBrowser(this.platformId)) { // 这里是浏览器端的代码 } else { // 这里是服务器端的代码 } } }

  3. 在你的组件中添加一些代码以检测页面是否已经初始化完成。如下所示:

    import { Component, OnDestroy, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { Subscription } from 'rxjs';

    @Component({ selector: 'app-about', templateUrl: './about.component.html', styleUrls: ['./about.component.css'] }) export class AboutComponent implements OnInit, OnDestroy { private routeSub$: Subscription;

    constructor(private route: ActivatedRoute) {}

    ngOnInit() { this.routeSub$ = this.route.url.subscribe(() => { // 这里是页面初始化完成后执行的代码 }); }

    ngOnDestroy() { this.routeSub$.unsubscribe(); } }

通过以上代码示例的改动,可以有效地解决 Angular Universal 无限加载的问题。

相关内容

热门资讯

德扑之星作弊事件,wepoke... 您好,wepoke辅助这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在...
wepoker有外挂吗,wpk... 1、wepoker有外挂吗,wpk微扑克辅助工具,智星德州菠萝有挂吗;代表性(透视辅助软件透明挂)高...
德扑ai软件购买,wpk透视挂... 德扑ai软件购买,wpk透视挂使用教程,智星德州菠萝开挂,您好,wpk透视挂使用教程这款游戏可以开挂...
微扑克辅助工具,wpk辅助,智... 微扑克辅助工具,wpk辅助,智星德州菠萝辅助工具是一款可以让一直输的玩家,快速成为一个“必胜”的ai...
wepoke有挂吗蓝鸟,wep... wepoke有挂吗蓝鸟,wepoke黑科技,智星德州菠萝开挂wepoke黑科技辅助器中分为三种模型:...
德扑智能ai,we-poker... 德扑智能ai,we-poker有挂吗,智星德州菠萝开挂是一款可以让一直输的玩家,快速成为一个“必胜”...
微扑克系统发牌逻辑,wepok... 微扑克系统发牌逻辑,wepoke到底有没有挂,智星德州菠萝外挂1、微扑克系统发牌逻辑ai辅助优化,微...
wepoke小技巧,wpk透视... wepoke小技巧,wpk透视外挂,智星德州菠萝辅助器免费下载是一款可以让一直输的玩家,快速成为一个...
德扑之星系统发牌机制,wepo... 德扑之星系统发牌机制,wepoke透视挂靠谱吗,智星德州菠萝偷偷看牌功能;是一款可以让一直输的玩家,...
aapoker有挂吗,wepo... aapoker有挂吗,wepoke人有挂吗,智星德州菠萝外挂1、wepoke人有挂吗ai辅助优化,w...