@symbo.ls/router 2.11.28 → 2.11.32

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 +10 -3
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -10,6 +10,7 @@ export const getActiveRoute = (level = 0, route = window.location.pathname) => {
10
10
  if (activeRoute) return `/${activeRoute}`
11
11
  }
12
12
 
13
+ export let lastPathname
13
14
  export let lastLevel = 0
14
15
 
15
16
  const defaultOptions = {
@@ -36,7 +37,7 @@ export const router = (
36
37
 
37
38
  const [pathname, hash] = path.split('#')
38
39
  const routeArray = pathname.split('/')
39
- const rootRoute = getActiveRoute(0)
40
+ const rootRoute = getActiveRoute(0, path)
40
41
 
41
42
  const authRedirect = redirectBasedOnAuth(rootRoute, element, element.state)
42
43
 
@@ -46,16 +47,22 @@ export const router = (
46
47
 
47
48
  const route = routeArray.join('/').replace('//', '/')
48
49
  const routeInContent = `/${routeArray[lastLevel + 1] || ''}`
50
+
49
51
  const content = element.routes[routeInContent] || element.routes['/*']
50
52
 
51
53
  const isModal = (findModal(element, element.state) || {}).FoundModal
52
54
  const isInitial = options.initialRender
55
+ const hashChanged = hash && hash !== window.location.hash.slice(1)
56
+ const pathChanged = pathname !== lastPathname
57
+ lastPathname = pathname
53
58
 
54
59
  if (content) {
55
60
  if (options.pushState) window.history.pushState(state, null, route + (hash ? `#${hash}` : ''))
56
61
 
57
- if (isInitial || (!isInitial && !isModal)) element.set({ tag: options.useFragment && 'fragment', extend: content })
58
- if (options.updateState) element.state.update({ route, hash })
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
+ }
59
66
 
60
67
  const rootNode = element.node
61
68
  const scrollNode = options.scrollDocument ? document.documentElement : rootNode
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbo.ls/router",
3
- "version": "2.11.28",
3
+ "version": "2.11.32",
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": "26b6500bc487650001f793925123dc2048065a87",
14
+ "gitHead": "747be57b5b769257c72f48dc611e1376af08d312",
15
15
  "source": "index.js"
16
16
  }