0

I'm trying to track down a value other than the hash symbol which can be passed to an <a href="#">Do not redirect</a> and not redirect the page.

My issue is that the # is being tracked by the browser history, and it's adding an extra step to clicking the back button. For example:

www.example.com?page=2#
*click back button in browser*
www.example.com?page=2
*click back button in browser*
www.example.com?page=1

I'm working in a library whereby the button MUST have a value passed (cannot be blank, otherwise the page will refresh). Any ideas? :(

Mmm Donuts
  • 9,551
  • 6
  • 27
  • 49

1 Answers1

1

If you don't need the # or the href then you should be using a button. Just style your button to look like a link. And then use JS function to handle the navigation changes that are needed. Here is a super basic example:

HTML

<button class="link" onclick="link('link to page 28')">looks like link</button>
<br>
<button onclick="link('button to page 27')">looks like button</button>

CSS

.link {
  border: none;
  background: none;
  color: blue;
  text-decoration: underline;
  cursor: pointer;
}

JS

function link(page) {
  console.log('redirect to ' + page);
  //do in app nav change, or update URL param, or window.location, etc
  // whatever your process is
}

Example: https://jsfiddle.net/Lhvgxr9q/3/

EnigmaRM
  • 7,523
  • 11
  • 46
  • 72