@domql/router 2.3.7 → 2.3.20

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 +7 -5
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  'use strict'
2
2
 
3
+ import { global } from '@domql/globals'
3
4
  import { merge } from '@domql/utils'
4
5
 
5
6
  export const getActiveRoute = (
6
- route = window.location.pathname, level
7
+ route = global.location.pathname, level
7
8
  ) => `/${route.split('/')[level + 1]}`
8
9
 
9
10
  export let lastLevel = 0
@@ -13,7 +14,8 @@ const defaultOptions = {
13
14
  pushState: true,
14
15
  scrollToTop: true,
15
16
  scrollToNode: false,
16
- useFragment: false
17
+ useFragment: false,
18
+ updateState: true
17
19
  }
18
20
 
19
21
  export const router = (
@@ -28,13 +30,13 @@ export const router = (
28
30
  const [pathname, hash] = (path).split('#')
29
31
 
30
32
  const route = getActiveRoute(pathname, options.level)
31
- const content = element.routes[route]
33
+ const content = element.routes[route] || element.routes['/*']
32
34
 
33
35
  if (content) {
34
- if (options.pushState) window.history.pushState(state, null, pathname + (hash ? `#${hash}` : ''))
36
+ if (options.pushState) global.history.pushState(state, null, pathname + (hash ? `#${hash}` : ''))
35
37
 
36
38
  element.set({ tag: options.useFragment && 'fragment', extend: content })
37
- element.state.update({ route, hash })
39
+ if (options.updateState) element.state.update({ route, hash })
38
40
 
39
41
  const rootNode = element.node
40
42
  if (options.scrollToTop) rootNode.scrollTo({ behavior: 'smooth', top: 0, left: 0 })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/router",
3
- "version": "2.3.7",
3
+ "version": "2.3.20",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -9,6 +9,6 @@
9
9
  "dependencies": {
10
10
  "@domql/utils": "latest"
11
11
  },
12
- "gitHead": "c8dcd776f492f22109580cc44aa5db7e13d43bde",
12
+ "gitHead": "e3a1ae560ae4606c7db7ee7108380ff29dfc291b",
13
13
  "source": "index.js"
14
14
  }