@jswork/history-change
v1.0.4
Published
Detect history/url change.
Downloads
16
Maintainers
Readme
history-change
Detect history/url change.
installation
npm install @jswork/history-change
use in app
import HistoryChange from '@jswork/history-change';
// app init
HistoryChange.init('hash');
// listen
window.addEventListener('historychange', (e) => {
const { action, history } = e.detail;
console.log('action/history :', action, history);
});
usage in browser
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>HistoryChange online version</title>
<script src="https://unpkg.com/@jswork/history-change"></script>
</head>
<body>
<nav>
<a href="#1">111</a>
<a href="#2">222</a>
<a href="#3">333</a>
<a href="#4">444</a>
</nav>
<script>
HistoryChange.init('hash');
window.addEventListener('historychange', (e) => {
const { action, history } = e.detail;
console.log('action/history :', action, history);
});
</script>
</body>
</html>
license
Code released under the MIT license.