Since you are dynamically loading these pages the correct one would be to use History API and save this "new state".
As you have not posted any code on how you will manage calls ( .load()
) this example assumes that:
- "rooteamento" will fire in
click
- the "route" will be a value in the
data-value=""
attribute on the
- a "container" will serve to show the loaded content
- returning to the default history state (null) the container is cleaned
EXAMPLE
<body>
<div id="container"></div>
<button type="button" data-value="pagina1.html" class="navigate">Carregar pagina1.html</button>
<button type="button" data-value="pagina2.html" class="navigate">Carregar pagina2.html</button>
<button type="button" data-value="pagina3.html" class="navigate">Carregar pagina3.html</button>
<script src="path/to/jequery.js"></script>
<script>
$('.navigate ').on('click', function() {
let target = $(this).attr('data-value')
$('#container').load(target, function() {
history.pushState(target, "", "/")
})
})
window.addEventListener("popstate", function(evt) {
if ( evt.state ) {
$('#container').load(evt.state)
} else {
$('#container').html('')
}
}, false)
</script>
</body>
In the pages a simple <h1>
indicating on which page this ... you can navigate the history "front" and "back".
The initial status of the history is null
, when it arrives in the initial state (if it returns) just display its default interface.