@jswork/history-change
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

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.

/@jswork/history-change/

    Package Sidebar

    Install

    npm i @jswork/history-change

    Homepage

    js.work

    Weekly Downloads

    0

    Version

    1.0.4

    License

    MIT

    Unpacked Size

    16.2 kB

    Total Files

    7

    Last publish

    Collaborators

    • afeiship