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