Skip to content

zhbhun/navigation-polyfill

Repository files navigation

English | 简体中文

navigation-polyfill implements part of the functionality of Navigation API based on Hisotry API emulation.

  • navigation.entries()

  • navigation.currentEntry

    • navigation.currentEntry.id
    • navigation.currentEntry.key
    • navigation.currentEntry.index
    • navigation.currentEntry.url
    • navigation.currentEntry.getState
  • navigation.canGoBack

  • navigation.canGoForward

  • navigation.navigate

  • navigation.reload

  • navigation.traverseTo

  • navigation.back

  • navigation.forward

  • navigation.onnavigate

  • navigation.onnavigatesuccess

  • navigation.onnavigateerror

  • navigation.oncurrententrychange

  • navigation.addEventListener()

  • navigation.removeEventListener()

Installation

npm install navigation-polyfill

Using

navigation-polyfill must be injected in the first line of code of the program.

// main.js
import 'navigation-polyfill';
// import 'others';
// ...

// case.js
import navigation from 'navigation-polyfill'
navigation.addEventListener("navigate", function (event) {
  event.preventDefault(); // blocking the opening new route
  console.log(event.navigationType); // 'reload' | 'push' | 'replace' | 'traverse'
  console.log(event.destination.id);
  console.log(event.destination.index);
  console.log(event.destination.url);
  console.log(navigation.entries());
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published