Browser Navigation keys (⬅ ➡) controller
Full control of back and forward keys on browser
It can:
- Listen to
back
, forward
and hashchange
events - Prevents any change on url or history state
- It doesn't have history functionallity (only overrides and listen 'back' and 'forward' keys)
- Ideal to make apps thats uses back button
- Can enable and disable forward key
import NavKeysController from 'nav-keys'
const options = {
allowHashchange: true
listenHashchange: true
}
const controller = new NavKeysController(window.history, options)
controller.url = 'home'
controller.listen(e => {
console.log(e)
})
controller.listen(e => {
e.stopPropagation()
})
controller.listen(e => {
console.log(e)
console.log(e.action)
console.log(e.location)
if (e.action === 'back') {
controller.url = 'previos page'
controller.enableForwardButton()
} else if (e.action === 'forward') {
controller.url = 'next page'
controller.disableForwardButton()
} else if (e.action === 'hashchange') {
controller.url = 'hash page'
}
})
Internet Explorer Compatibility
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
<script src="nav-keys.js"></script>
<script>
var controller = new NavKeysController(window.history)
</script>