JSFiddle - React, Tailwind, and code Playground
HTML
<input id="Ancre">
<nav>
<a href="#id1">ancre 1</a>
<a href="#id2">ancre 2</a>
<a href="#id3">ancre 3</a>
<a href="#id4">ancre 4</a>
<a href="#id5">ancre 5</a>
<a href="#id6">ancre 6</a>
</nav>
JavaScript
function locationHashChanged() {
document.getElementById("Ancre").value= location.hash;
}
window.addEventListener('hashchange', locationHashChanged);