|
@@ -13,19 +13,43 @@ const _historyWrap = function (type) {
|
|
|
history.pushState = _historyWrap('pushState')
|
|
|
history.replaceState = _historyWrap('replaceState')
|
|
|
|
|
|
+window.addEventListener('hashchange', function () {
|
|
|
+ getRouterType()
|
|
|
+})
|
|
|
|
|
|
-window.addEventListener('hashchange', function (event) {
|
|
|
- console.log('hashchange', event)
|
|
|
+window.addEventListener('popstate', function () {
|
|
|
+ getRouterType()
|
|
|
})
|
|
|
|
|
|
-window.addEventListener('popstate', function (event) {
|
|
|
- console.log('popstate', event)
|
|
|
+window.addEventListener('pushState', function () {
|
|
|
+ getRouterType()
|
|
|
})
|
|
|
|
|
|
-window.addEventListener('pushState', function (e) {
|
|
|
- console.log('change pushState', e)
|
|
|
+window.addEventListener('replaceState', function () {
|
|
|
+ getRouterType()
|
|
|
})
|
|
|
|
|
|
-window.addEventListener('replaceState', function (e) {
|
|
|
- console.log('change replaceState', e)
|
|
|
-})
|
|
|
+let router_data = []
|
|
|
+
|
|
|
+const getRouterType = () => {
|
|
|
+ let key = history?.state?.key
|
|
|
+ if (!key) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let index = router_data.indexOf(key)
|
|
|
+ if (index < 0) {
|
|
|
+ // 没有此页面
|
|
|
+ router_data.push(key)
|
|
|
+ index = router_data.indexOf(key)
|
|
|
+ }
|
|
|
+ let type = ''
|
|
|
+ if (router_data.length == 1) {
|
|
|
+ type = 'first&last'
|
|
|
+ } else if (index + 1 == router_data.length) {
|
|
|
+ type = 'last'
|
|
|
+ } else if (index == 0) {
|
|
|
+ type = 'first'
|
|
|
+ }
|
|
|
+ return type
|
|
|
+}
|
|
|
+
|