1.0.4 • Published 7 months ago

@jswork/history-change v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

history-change

Detect history/url change.

version license size download

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.

1.0.4

7 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago