href="#";导致位置地址改变,我们可以避免吗? [英] href="#" causes location address to change, can we avoid it?

查看:39
本文介绍了href="#";导致位置地址改变,我们可以避免吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多选项卡可以处理特殊逻辑,因此不会发生位置栏地址更改.我有以下

I have a number of tabs that I handle special logic so no location bar address change should occur. I have the following

<a href="#">Home</a>

这符合预期,即当鼠标悬停在按钮上时,它给了我手鼠标指针,但点击然后开始更改路线.我希望能够阻止这种情况.

This behaves as expected, i.e. it gives me the hand mouse pointer when hovering over the buttons but clicking on then starts the route change. I want to be able to stop this.

我尝试删除 href 或设置 href="",似乎取得了一些成功,但在悬停时却出现了意想不到的结果.

I tried just remove the href or setting href="", seemed to have some success but it gave unexpected results when hovering.

这里的最佳实践是什么?我必须删除href吗?那么我将需要使用 CSS 设置选项卡的样式,以便在悬停时为我提供鼠标指针?如果我将 href="#" 留在链接中,那么这会导致路由更改,这不是我想要的.

What is the best practice here? Do I have to remove the href? So then I will need to style the tab using CSS to give me the mouse pointer when hovering? If I do leave the href="#" in the link then this causes a change of routing which is not what I was looking for.

我实际上在每个选项卡的 ngClick 中处理我的登录.这个逻辑一定不能改变路由.

I actually handle my login in a ngClick for each tab. This logic must not change the route.

有什么想法吗?

推荐答案

尝试这样做:

<a href="javascript:void(0);">Home</a>

这篇关于href="#";导致位置地址改变,我们可以避免吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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