同一页面中的Angular 6路由器链接问题 [英] Angular 6 router link issue in the same page

查看:72
本文介绍了同一页面中的Angular 6路由器链接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个链接:

  1. ['/productlist',1000]
  2. ['/productlist',1001]
  1. ['/productlist',1000]
  2. ['/productlist',1001]

这两个链接在同一页面上.如果我是第一次单击任何链接.它正在重定向到页面,但是如果我单击其他链接,则该页面不起作用.

These two links are on the same page. If I click on any link for the first time. It is redirecting to the page, but if I click on the other link it is not working.

component.html代码

component.html code

<a class="dropdown-item" (click)="GetProductList(subitem.SubCategoryID)">
 <i class="mdi mdi-chevron-right" aria-hidden="true"></i> 
 {{ subitem.SubCategoryName}}
</a> 

GetProductList(SubCategoryID){ 
    this.router.navigate(['/productlist',SubCategoryID]); 
}

推荐答案

由于角度,它是同一条路线-不会重新加载.

Since for angular it is same route - it is not reloaded.

两种可能的解决方案:

  1. 在组件中订阅this.route.params并做出相应的反应,例如在 Angular 4 routerLink-重新加载当前路由

在Angular 5中,有一个用于重新加载活动路径的选项:

in Angular 5 there is an option for reloading the active route:

RouterModule.forRoot(routes,{onSameUrlNavigation:'reload'}

RouterModule.forRoot(routes, {onSameUrlNavigation: ‘reload’}

尝试

这篇关于同一页面中的Angular 6路由器链接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆