Healyhatman
Healyhatman

Reputation: 1659

anchor menu links broken by history.pushState

I have a series of menu anchor / hash links on the left hand side of my site. For example

<a href="#settings" id="" class="dropdown-toggle" data-toggle="">

These all work fine.

I have a list of transactions and the button opens the edit form using AJAX, and I use

history.pushState({}, null, `/transaction/${id}/edit`);

to change the URL and add it to the history stack, and an appropriate popstate to reload the main page when clicking back.

Problem is after the pushState, a click on one of those links will instead reload the page and append the anchor name to the url, so it looks like say /transaction/3354/edit#settings, instead of just opening the dropdown.

Why, please, and how do I stop it happening

Upvotes: 1

Views: 613

Answers (1)

Healyhatman
Healyhatman

Reputation: 1659

Correct me if this is the wrong answer but I changed them from href="#" to href="javascript:;" and it seems to be okay now

Upvotes: 1

Related Questions