@symbo.ls/router 2.3.10 → 2.8.3

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 +18 -9
  2. package/package.json +3 -2
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  import { merge } from '@domql/utils'
4
+ import { setCookie } from '@domql/cookie'
4
5
  import { redirectBasedOnAuth } from '@symbo.ls/auth-redirect'
5
6
 
6
7
  export const getActiveRoute = (
@@ -26,18 +27,26 @@ export const router = (
26
27
  options = defaultOptions
27
28
  ) => {
28
29
  merge(options, defaultOptions)
29
- lastLevel = options.lastLevel
30
-
31
- const rootRoute = getActiveRoute(path, 0)
32
- path = redirectBasedOnAuth(element, element.state, { route: rootRoute })
30
+ lastLevel = options.level
33
31
 
34
32
  const [pathname, hash] = (path).split('#')
33
+ const routeArray = pathname.split('/')
34
+ const rootRoute = `/${routeArray[1] || ''}`
35
+
36
+ const authRedirect = redirectBasedOnAuth(element, element.state, { route: rootRoute })
35
37
 
36
- const route = getActiveRoute(pathname, options.level)
37
- const content = element.routes[route] || element.routes['/*']
38
+ if (authRedirect && rootRoute !== authRedirect) {
39
+ // if (!element.state.__root.userToken)
40
+ routeArray[1] = authRedirect.slice(1)
41
+ console.log(authRedirect, routeArray)
42
+ }
43
+
44
+ const route = routeArray.join('/')
45
+ const routeInContent = `/${routeArray[lastLevel + 1] || ''}`
46
+ const content = element.routes[routeInContent] || element.routes['/*']
38
47
 
39
48
  if (content) {
40
- if (options.pushState) window.history.pushState(state, null, pathname + (hash ? `#${hash}` : ''))
49
+ if (options.pushState) window.history.pushState(state, null, route + (hash ? `#${hash}` : ''))
41
50
 
42
51
  element.set({ tag: options.useFragment && 'fragment', extend: content })
43
52
  if (options.updateState) element.state.update({ route, hash })
@@ -53,7 +62,7 @@ export const router = (
53
62
  rootNode.scrollTo({ behavior: 'smooth', top, left: 0 })
54
63
  }
55
64
  }
56
-
57
- setCookie('route', path)
65
+
66
+ if (route !== '/*') setCookie('route', route)
58
67
  }
59
68
  }
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@symbo.ls/router",
3
- "version": "2.3.10",
3
+ "version": "2.8.3",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
7
  "vpatch": "npm version patch && npm publish --access public"
8
8
  },
9
9
  "dependencies": {
10
+ "@domql/cookie": "latest",
10
11
  "@domql/utils": "latest",
11
12
  "@symbo.ls/auth-redirect": "latest"
12
13
  },
13
- "gitHead": "66641a0ee9c94ecbe631b7b92e2018ad18af387b",
14
+ "gitHead": "14dff7d74c523437405b3e770acd7d60b3e92b69",
14
15
  "source": "index.js"
15
16
  }