Mike P
Mike P

Reputation: 2877

Angular-ui-router and href='#'

I'm using angular-ui-router and have an issue with empty a tags, like href='#'. I'm using bootstrap, which makes extensive use of href='#' for dropdowns and such. The problem is if a user selects a dropdown item then the router interprets that as a state change, which in this case is to the home page.

Is there an easy way to stop this behavior without having to resort to changing all the href='#' to href=''.

Upvotes: 12

Views: 10891

Answers (3)

adam0101
adam0101

Reputation: 30995

Just remove the href tag completely from your anchor tag. It's still a perfectly valid tag without it.

Or if you're currently using ui-sref in the anchor tag, you could actually use the href attribute instead to go to the route that the state is mapped to.

Upvotes: 11

Devin McQueeney
Devin McQueeney

Reputation: 1287

I use this:

<a href-void>Click me! I don't do anything, but i'm still a link!</a>

Upvotes: 1

Hichem ben chaabene
Hichem ben chaabene

Reputation: 145

you can use this, so you can preserve the link and basically do nothing when its clicked

<a ui-sref="state" href="javascript:void(0);">Your link</a>

Upvotes: 2

Related Questions