@symbo.ls/router 2.11.29 → 2.11.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +40 -23
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export const getActiveRoute = (level = 0, route = window.location.pathname) => {
|
|
|
10
10
|
if (activeRoute) return `/${activeRoute}`
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export let lastPathname
|
|
13
14
|
export let lastLevel = 0
|
|
14
15
|
|
|
15
16
|
const defaultOptions = {
|
|
@@ -51,36 +52,52 @@ export const router = (
|
|
|
51
52
|
|
|
52
53
|
const isModal = (findModal(element, element.state) || {}).FoundModal
|
|
53
54
|
const isInitial = options.initialRender
|
|
55
|
+
const hashChanged = hash && hash !== window.location.hash.slice(1)
|
|
56
|
+
const pathChanged = pathname !== lastPathname
|
|
57
|
+
lastPathname = pathname
|
|
54
58
|
|
|
55
|
-
if (content)
|
|
56
|
-
|
|
59
|
+
if (!content) return
|
|
60
|
+
if (options.pushState) {
|
|
61
|
+
window.history.pushState(state, null, route + (hash ? `#${hash}` : ''))
|
|
62
|
+
}
|
|
57
63
|
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
if (pathChanged || !hashChanged) {
|
|
65
|
+
const hasSet = isInitial || (!isInitial && !isModal)
|
|
60
66
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (options.scrollToTop) {
|
|
64
|
-
scrollNode.scrollTo({
|
|
65
|
-
...(options.scrollToOptions || {}), top: 0, left: 0
|
|
66
|
-
})
|
|
67
|
+
if (options.updateState) {
|
|
68
|
+
element.state.update({ route, hash }, { preventContentUpdate: true })
|
|
67
69
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
|
|
71
|
+
if (hasSet) {
|
|
72
|
+
element.set({
|
|
73
|
+
tag: options.useFragment && 'fragment',
|
|
74
|
+
extend: content
|
|
71
75
|
})
|
|
72
76
|
}
|
|
77
|
+
}
|
|
73
78
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
const rootNode = element.node
|
|
80
|
+
const scrollNode = options.scrollDocument ? document.documentElement : rootNode
|
|
81
|
+
if (options.scrollToTop) {
|
|
82
|
+
scrollNode.scrollTo({
|
|
83
|
+
...(options.scrollToOptions || {}), top: 0, left: 0
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
if (options.scrollToNode) {
|
|
87
|
+
content.content.node.scrollTo({
|
|
88
|
+
...(options.scrollToOptions || {}), top: 0, left: 0
|
|
89
|
+
})
|
|
90
|
+
}
|
|
83
91
|
|
|
84
|
-
|
|
92
|
+
if (hash) {
|
|
93
|
+
const activeNode = document.getElementById(hash)
|
|
94
|
+
if (activeNode) {
|
|
95
|
+
const top = activeNode.getBoundingClientRect().top + rootNode.scrollTop - options.scrollToOffset || 0
|
|
96
|
+
scrollNode.scrollTo({
|
|
97
|
+
...(options.scrollToOptions || {}), top, left: 0
|
|
98
|
+
})
|
|
99
|
+
}
|
|
85
100
|
}
|
|
101
|
+
|
|
102
|
+
if (route !== '/*') setCookie('route', route)
|
|
86
103
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/router",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.34",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
@@ -11,6 +11,6 @@
|
|
|
11
11
|
"@domql/utils": "latest",
|
|
12
12
|
"@symbo.ls/auth-redirect": "latest"
|
|
13
13
|
},
|
|
14
|
-
"gitHead": "
|
|
14
|
+
"gitHead": "a9875f5261165cbef5c9e6344f319636cb89c3f2",
|
|
15
15
|
"source": "index.js"
|
|
16
16
|
}
|