@symbo.ls/router 2.11.32 → 2.11.35

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 +42 -28
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -21,6 +21,7 @@ const defaultOptions = {
21
21
  scrollToNode: false,
22
22
  scrollDocument: false,
23
23
  useFragment: false,
24
+ authCheck: true,
24
25
  updateState: true,
25
26
  scrollToOffset: 120,
26
27
  scrollToOptions: { behavior: 'smooth' }
@@ -39,10 +40,12 @@ export const router = (
39
40
  const routeArray = pathname.split('/')
40
41
  const rootRoute = getActiveRoute(0, path)
41
42
 
42
- const authRedirect = redirectBasedOnAuth(rootRoute, element, element.state)
43
+ if (options.authCheck) {
44
+ const authRedirect = redirectBasedOnAuth(rootRoute, element, element.state)
43
45
 
44
- if (authRedirect && rootRoute !== authRedirect) {
45
- routeArray[1] = authRedirect.slice(1)
46
+ if (authRedirect && rootRoute !== authRedirect) {
47
+ routeArray[1] = authRedirect.slice(1)
48
+ }
46
49
  }
47
50
 
48
51
  const route = routeArray.join('/').replace('//', '/')
@@ -56,37 +59,48 @@ export const router = (
56
59
  const pathChanged = pathname !== lastPathname
57
60
  lastPathname = pathname
58
61
 
59
- if (content) {
60
- if (options.pushState) window.history.pushState(state, null, route + (hash ? `#${hash}` : ''))
62
+ if (!content) return
63
+ if (options.pushState) {
64
+ window.history.pushState(state, null, route + (hash ? `#${hash}` : ''))
65
+ }
61
66
 
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
- }
67
+ if (pathChanged || !hashChanged) {
68
+ const hasSet = isInitial || (!isInitial && !isModal)
66
69
 
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
- })
70
+ if (options.updateState) {
71
+ element.state.update({ route, hash }, { preventContentUpdate: true })
73
72
  }
74
- if (options.scrollToNode) {
75
- content.content.node.scrollTo({
76
- ...(options.scrollToOptions || {}), top: 0, left: 0
73
+
74
+ if (hasSet) {
75
+ element.set({
76
+ tag: options.useFragment && 'fragment',
77
+ extend: content
77
78
  })
78
79
  }
80
+ }
79
81
 
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
- }
82
+ const rootNode = element.node
83
+ const scrollNode = options.scrollDocument ? document.documentElement : rootNode
84
+ if (options.scrollToTop) {
85
+ scrollNode.scrollTo({
86
+ ...(options.scrollToOptions || {}), top: 0, left: 0
87
+ })
88
+ }
89
+ if (options.scrollToNode) {
90
+ content.content.node.scrollTo({
91
+ ...(options.scrollToOptions || {}), top: 0, left: 0
92
+ })
93
+ }
89
94
 
90
- if (route !== '/*') setCookie('route', route)
95
+ if (hash) {
96
+ const activeNode = document.getElementById(hash)
97
+ if (activeNode) {
98
+ const top = activeNode.getBoundingClientRect().top + rootNode.scrollTop - options.scrollToOffset || 0
99
+ scrollNode.scrollTo({
100
+ ...(options.scrollToOptions || {}), top, left: 0
101
+ })
102
+ }
91
103
  }
104
+
105
+ if (route !== '/*') setCookie('route', route)
92
106
  }
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.35",
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": "9833e01499952b3973fb9b67ec917bac5fea42f8",
15
15
  "source": "index.js"
16
16
  }