Angular 2中的被动链接-< a href =“"”当量 [英] Passive Link in Angular 2 - <a href=""> equivalent

查看:99
本文介绍了Angular 2中的被动链接-< a href =“"”当量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Angular 1.x中,我可以执行以下操作来创建基本上不执行任何操作的链接:

In Angular 1.x I can do the following to create a link which does basically nothing:

<a href="">My Link</a>

但是相同的标签会导航到Angular 2中的应用库。与Angular中的等效2?

But the same tag navigates to the app base in Angular 2. What is the equivalent of that in Angular 2?

编辑:看起来像是Angular 2 Router中的错误,现在有关于github的公开问题

It looks like a bug in the Angular 2 Router and now there is an open issue on github about that.

我正在寻找一个

推荐答案

如果您有 Angular 5 strong>或更高,只需更改

If you have Angular 5 or above, just change

<a href="" (click)="passTheSalt()">Click me</a>

进入

<a [routerLink]="" (click)="passTheSalt()">Click me</a>

将鼠标悬停在链接上时会显示带有手形图标的链接,单击该链接不会触发任何操作

A link will be displayed with a hand icon when hovering over it and clicking it won't trigger any route.

注意:如果要保留查询参数,则应设置 queryParamsHandling 保留 的选项:

Note: If you want to keep the query parameters, you should set queryParamsHandling option to preserve:

<a [routerLink]=""
   queryParamsHandling="preserve"
   (click)="passTheSalt()">Click me</a>

这篇关于Angular 2中的被动链接-&lt; a href =“&quot;”当量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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