href=“#” causes location address to change, can we avoid it?

半城伤御伤魂 提交于 2019-12-01 08:26:43

Try doing:

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

If you don't use the <base> tag, you can simply use:

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

Indeed, according to the documentation:

[...] the default action is prevented when href attribute is empty.

Well, the documentation is wrong, and the real behaviour is actually to prevent the default action when the href attribute is equal to page location. That's a problem when you're using <base>. In this case, you have two choices:

  • Forget the href attribute. That works fine, but your page will not be valid anymore, since the href attribute is mandatory for a <a> tag.
  • Create your own directive, for instance aEmpty, whose goal is simply to fill the href attribute of a real <a> with the current value of $location.path().

In all cases, you'd better to actually use CSS to style your link, because that's always a bad idea to rely on the default behaviour of the browsers.

user2793135

Replace href with ng_click.

To get the hand mouse pointer, add the css style:

a { cursor: pointer ; }
a:hover   { color: #00c }  /* user hovers     */
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!