Angular在打开新标签页时一直重定向到主页的路由问题。
创始人
2024-10-30 19:30:27
0

这个问题通常是由于在Angular应用程序中使用了HTML5模式而不是Hash模式所致。解决此问题的一种方法是使用Hash模式,可以在app.module.ts中将路由器的配置更改为HashLocationStrategy。

import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { LocationStrategy, HashLocationStrategy } from '@angular/common'; import { RouterModule, Routes } from '@angular/router';

const appRoutes: Routes = [ // Your routes here ];

@NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, RouterModule.forRoot(appRoutes) ], providers: [{ provide: LocationStrategy, useClass: HashLocationStrategy }], bootstrap: [AppComponent] }) export class AppModule { }

此外,还可以尝试在根组件中添加以下代码来解决路由问题。

export class AppComponent { constructor(private router: Router) { this.router.routeReuseStrategy.shouldReuseRoute = function() { return false; };

this.router.events.subscribe((evt) => {
  if (evt instanceof NavigationEnd) {
    this.router.navigated = false;
    window.scrollTo(0, 0);
  }
});

} }

这将防止路由重用,并确保在加载新标签页时重新加载组件。

相关内容

热门资讯

透视有挂!aapoker透视插... 1、透视有挂!aapoker透视插件(透视)往昔真的是有挂(详细辅助2025新版教程);详细教程。2...
透视软件(WePoKer)aa... 透视软件(WePoKer)aa扑克网上的挂真的(透视)详细辅助必赢教程;亲真的是有正版授权,小编(透...
透视总结!德普之星透视辅助插件... 透视总结!德普之星透视辅助插件(透视)详细辅助微扑克教程(本来是真的有挂)小薇(透视辅助)致您一封信...
透视美元局!德州局透视脚本免费... 此外,数据分析德州(德州局透视脚本免费版下载手机版)辅助神器app还具备辅助透视行为开挂功能,通过对...
透视总结(WePoKer)微扑... 透视总结(WePoKer)微扑克有没有辅助挂(透视)详细辅助新2025教程;微扑克有没有辅助挂软件透...
透视讲解!智星德州菠萝插件官网... 透视讲解!智星德州菠萝插件官网(透视)详细辅助2025新版(本来有挂);暗藏猫腻,小编详细说明智星德...
透视科技(wePoke)wep... 透视科技(wePoke)wepoke ai代打辅助(透视)详细辅助透明挂教程;小薇(透视辅助)致您一...
透视透视!wejoker辅助脚... 透视透视!wejoker辅助脚本(透视)真是是有挂(详细辅助可靠技巧),支持语音通讯、好友开房及战队...
透视好牌!wepoker透视脚... 透视好牌!wepoker透视脚本免费(透视)详细辅助安装教程(一贯是有挂);1、用户打开应用后不用登...
透视攻略(WEPOKE)传奇扑... 1、透视攻略(WEPOKE)传奇扑克辅助(透视)详细辅助微扑克教程。2、传奇扑克辅助透视辅助简单,传...