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软件透明挂价格!红龙扑克是真是假,gg扑克软件,解密教程(起初是真的有挂)准备好在红龙扑...
黑科技挂!(wEpoKe)软件... 您好,wePokE这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在这款...
德州之星辅助软件介绍!德州po... 1、德州之星辅助软件介绍!德州poker外挂,德州之星可能有外挂吗,攻略教程(起初真的有挂)(UU ...
黑科技了解!(pokerrrr... 黑科技了解!(pokerrrr2俱乐部)外挂辅助挂,(pokernow德州)其实真的有挂,解密教程(...
wpk德州职业代打!约局互娱辅... 这是一款非常优秀的wpk微扑克系统发牌规律 ia辅助检测软件,能够让你了解到wpk微扑克系统发牌规律...
黑科技美元局!(wepOke)... 1、黑科技美元局!(wepOke)软件透明挂,(wEPOKE)其实真的是有挂,AI教程(有挂透视);...
黑科技真的!(WepoKe)软... 黑科技真的!(WepoKe)软件透明挂,(wEpoKe)原本是真的有挂,必胜教程(有挂方法)是一款可...
wepoke到底有没有挂!德扑... 这是一款非常优秀的微扑克怎么用ai辅助 ia辅助检测软件,能够让你了解到微扑克怎么用ai辅助中牌率当...
黑科技攻略!(WepOke)软... 黑科技攻略!(WepOke)软件透明挂,(WepokE)原本真的有挂,2025教程(有挂辅助)是由北...
德州ai辅助怎么打!德州之星辅... 此外,数据分析德州(德州之星辅助怎么用)辅助神器app还具备辅助透视行为开挂功能,通过对客户德州之星...