@symbo.ls/router 2.12.95 → 2.12.103
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 +12 -14
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import { isModalRoute } from '@symbo.ls/platform-utils'
|
|
6
|
-
import { merge } from 'smbls'
|
|
3
|
+
import utils from '@domql/utils'
|
|
4
|
+
const { setCookie, merge } = utils
|
|
7
5
|
|
|
8
6
|
export const getLocationPath = (index = 0, route = window.location.pathname) => {
|
|
9
7
|
const routeArray = route.split('/')
|
|
@@ -21,7 +19,7 @@ export let lastPathname
|
|
|
21
19
|
export let lastLevel = 0
|
|
22
20
|
|
|
23
21
|
const defaultOptions = {
|
|
24
|
-
window,
|
|
22
|
+
window: globalThis,
|
|
25
23
|
level: lastLevel,
|
|
26
24
|
initialRender: false,
|
|
27
25
|
pushState: true,
|
|
@@ -43,12 +41,13 @@ const defaultOptions = {
|
|
|
43
41
|
scrollToOptions: { behavior: 'smooth' }
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
export
|
|
44
|
+
export function router (
|
|
47
45
|
path = '/',
|
|
48
|
-
|
|
46
|
+
el,
|
|
49
47
|
state = {},
|
|
50
48
|
passedOptions = {}
|
|
51
|
-
)
|
|
49
|
+
) {
|
|
50
|
+
const element = el || (this && this.getRoot())
|
|
52
51
|
const options = merge(passedOptions, defaultOptions)
|
|
53
52
|
lastLevel = options.level
|
|
54
53
|
|
|
@@ -59,8 +58,7 @@ export const router = (
|
|
|
59
58
|
let routeArray = pathname.split('/')
|
|
60
59
|
|
|
61
60
|
if (options.authCheck) {
|
|
62
|
-
const authRedirect = redirectBasedOnAuth
|
|
63
|
-
|
|
61
|
+
const authRedirect = element.call('redirectBasedOnAuth', rootRoute)
|
|
64
62
|
if (authRedirect && rootRoute !== authRedirect) {
|
|
65
63
|
routeArray = authRedirect.split('/')
|
|
66
64
|
}
|
|
@@ -73,7 +71,7 @@ export const router = (
|
|
|
73
71
|
|
|
74
72
|
const content = element.routes[routeInContent] || element.routes['/*']
|
|
75
73
|
|
|
76
|
-
const wasModal = isModalRoute
|
|
74
|
+
const wasModal = element.call('isModalRoute', options.window.location.pathname.split('#')[0])
|
|
77
75
|
const isInitial = options.initialRender
|
|
78
76
|
const hashChanged = hash && hash !== options.window.location.hash
|
|
79
77
|
const pathChanged = pathname !== lastPathname
|
|
@@ -86,7 +84,7 @@ export const router = (
|
|
|
86
84
|
}, null, route + (search ? `${search}` : '') + (hash ? `${hash}` : ''))
|
|
87
85
|
}
|
|
88
86
|
|
|
89
|
-
const isModal = !!isModalRoute
|
|
87
|
+
const isModal = !!element.call('isModalRoute', pathname)
|
|
90
88
|
|
|
91
89
|
if (pathChanged || !hashChanged) {
|
|
92
90
|
// const rootRouteHasChanged = rootRoute !== element.state.rootRoute
|
|
@@ -122,7 +120,7 @@ export const router = (
|
|
|
122
120
|
}
|
|
123
121
|
|
|
124
122
|
const rootNode = element.node
|
|
125
|
-
const scrollNode = options.scrollDocument ? document.documentElement : rootNode
|
|
123
|
+
const scrollNode = options.scrollDocument ? options.window.document.documentElement : rootNode
|
|
126
124
|
if (options.scrollToTop) {
|
|
127
125
|
scrollNode.scrollTo({
|
|
128
126
|
...(options.scrollToOptions || {}), top: 0, left: 0
|
|
@@ -135,7 +133,7 @@ export const router = (
|
|
|
135
133
|
}
|
|
136
134
|
|
|
137
135
|
if (hash) {
|
|
138
|
-
const activeNode = document.getElementById(hash)
|
|
136
|
+
const activeNode = options.window.document.getElementById(hash.slice(1))
|
|
139
137
|
if (activeNode) {
|
|
140
138
|
const top = activeNode.getBoundingClientRect().top + rootNode.scrollTop - options.scrollToOffset || 0
|
|
141
139
|
scrollNode.scrollTo({
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/router",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.103",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"vpatch": "npm version patch && npm publish --access public"
|
|
8
9
|
},
|
|
@@ -11,6 +12,6 @@
|
|
|
11
12
|
"@domql/utils": "latest",
|
|
12
13
|
"@symbo.ls/auth-redirect": "latest"
|
|
13
14
|
},
|
|
14
|
-
"gitHead": "
|
|
15
|
+
"gitHead": "3f66a78d3d2bec315697ed20ec09b4045b3f78ce",
|
|
15
16
|
"source": "index.js"
|
|
16
17
|
}
|