首页 > 解决方案 > Angular 6:路由路径附加在查询字符串之后

问题描述

我的情况就像我的应用程序正在 iframe 中加载。所以首先它会从 URL 中读取查询字符串并根据值重定向应用程序。但每次这样做时,它都会将路由路径附加到查询字符串的末尾。我的代码。

应用程序组件

 ngOnInit(){
 if (conditionmatch) {
    this.router.navigate(['template-not-found'])
  }
}

路由模块

{ path: 'template-not-found', component: TemplateNotFoundComponent },

例如,我的初始条件是https://localhost:44351/id=152&projId=130
所以在条件匹配之后它会转到该页面,但它会在末尾附加路由路径。https://localhost:44351/id=152&projId=130#/template-not-found

我应该如何处理它以便它出现在查询字符串之前?

标签: angular

解决方案


要相对于根导航,您必须在第一段路径之前放置一个斜杠。

所以试试

ngOnInit(){
 if (conditionmatch) {
    this.router.navigate(['/template-not-found'])
  }
}

推荐阅读