@symbo.ls/router 2.11.32 → 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.
Files changed (2) hide show
  1. package/index.js +36 -25
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -56,37 +56,48 @@ export const router = (
56
56
  const pathChanged = pathname !== lastPathname
57
57
  lastPathname = pathname
58
58
 
59
- if (content) {
60
- if (options.pushState) window.history.pushState(state, null, route + (hash ? `#${hash}` : ''))
59
+ if (!content) return
60
+ if (options.pushState) {
61
+ window.history.pushState(state, null, route + (hash ? `#${hash}` : ''))
62
+ }
61
63
 
62
- if (pathChanged || !hashChanged) {
63
- if (isInitial || (!isInitial && !isModal)) element.set({ tag: options.useFragment && 'fragment', extend: content })
64
- if (options.updateState) element.state.update({ route, hash })
65
- }
64
+ if (pathChanged || !hashChanged) {
65
+ const hasSet = isInitial || (!isInitial && !isModal)
66
66
 
67
- const rootNode = element.node
68
- const scrollNode = options.scrollDocument ? document.documentElement : rootNode
69
- if (options.scrollToTop) {
70
- scrollNode.scrollTo({
71
- ...(options.scrollToOptions || {}), top: 0, left: 0
72
- })
67
+ if (options.updateState) {
68
+ element.state.update({ route, hash }, { preventContentUpdate: true })
73
69
  }
74
- if (options.scrollToNode) {
75
- content.content.node.scrollTo({
76
- ...(options.scrollToOptions || {}), top: 0, left: 0
70
+
71
+ if (hasSet) {
72
+ element.set({
73
+ tag: options.useFragment && 'fragment',
74
+ extend: content
77
75
  })
78
76
  }
77
+ }
79
78
 
80
- if (hash) {
81
- const activeNode = document.getElementById(hash)
82
- if (activeNode) {
83
- const top = activeNode.getBoundingClientRect().top + rootNode.scrollTop - options.scrollToOffset || 0
84
- scrollNode.scrollTo({
85
- ...(options.scrollToOptions || {}), top, left: 0
86
- })
87
- }
88
- }
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
+ }
89
91
 
90
- if (route !== '/*') setCookie('route', route)
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
+ }
91
100
  }
101
+
102
+ if (route !== '/*') setCookie('route', route)
92
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbo.ls/router",
3
- "version": "2.11.32",
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": "747be57b5b769257c72f48dc611e1376af08d312",
14
+ "gitHead": "a9875f5261165cbef5c9e6344f319636cb89c3f2",
15
15
  "source": "index.js"
16
16
  }