Skip to content

Latest commit

 

History

History
54 lines (44 loc) · 1.41 KB

README_zh-CN.md

File metadata and controls

54 lines (44 loc) · 1.41 KB

English | 简体中文

navigation-polyfill 基于 Hisotry API 模拟实现了 Navigation API 的部分功能。

  • 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()

安装

npm install navigation-polyfill

使用

navigation-polyfill 必须在程序的第一行代码中注入。

// 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());
});