@symbo.ls/router 2.12.65 → 2.12.68

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 +12 -11
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -11,9 +11,9 @@ export const getLocationPath = (index = 0, route = window.location.pathname) =>
11
11
  if (activeRoute) return `/${activeRoute}`
12
12
  }
13
13
 
14
- export const getLastLocationPath = (route = window.location.pathname) => {
14
+ export const getLastLocationPath = (level = 0, route = window.location.pathname) => {
15
15
  const routeArray = route.split('/')
16
- const activeRoute = routeArray[routeArray.length - 1]
16
+ const activeRoute = routeArray[routeArray.length - level - 1]
17
17
  if (activeRoute) return `/${activeRoute}`
18
18
  }
19
19
 
@@ -21,6 +21,7 @@ export let lastPathname
21
21
  export let lastLevel = 0
22
22
 
23
23
  const defaultOptions = {
24
+ window,
24
25
  level: lastLevel,
25
26
  initialRender: false,
26
27
  pushState: true,
@@ -32,8 +33,8 @@ const defaultOptions = {
32
33
  updateState: true,
33
34
  updateStateOptions: {
34
35
  preventUpdateTriggerStateUpdate: true,
35
- preventContentUpdate: true,
36
- preventUpdate: ['Modal', 'MainHeaderCaptions', 'HeaderSubAside']
36
+ // preventContentUpdate: true,
37
+ preventUpdate: ['MainHeaderCaptions', 'HeaderSubAside']
37
38
  },
38
39
  preventUpdate: ['MainHeaderCaptions', 'HeaderSubAside'],
39
40
  setOptions: {},
@@ -69,23 +70,22 @@ export const router = (
69
70
 
70
71
  const content = element.routes[routeInContent] || element.routes['/*']
71
72
 
72
- const wasModal = isModalRoute(window.location.pathname.split('#')[0], element)
73
+ const wasModal = isModalRoute(options.window.location.pathname.split('#')[0], element)
73
74
  const isInitial = options.initialRender
74
- const hashChanged = hash && hash !== window.location.hash.slice(1)
75
+ const hashChanged = hash && hash !== options.window.location.hash.slice(1)
75
76
  const pathChanged = pathname !== lastPathname
76
77
  lastPathname = pathname
77
78
 
78
79
  if (!content) return
79
80
  if (options.pushState) {
80
- window.history.pushState({
81
- prevUrl: window.location.href, ...state
81
+ options.window.history.pushState({
82
+ prevUrl: options.window.location.href, ...state
82
83
  }, null, route + (hash ? `#${hash}` : ''))
83
84
  }
84
85
 
85
86
  const isModal = isModalRoute(pathname, element)
86
87
 
87
88
  if (pathChanged || !hashChanged) {
88
- const hasSet = isInitial || (!isInitial && !isModal)
89
89
  // const rootRouteHasChanged = rootRoute !== element.state.rootRoute
90
90
  // || (!rootRouteHasChanged && { preventUpdateTriggerStateUpdate: true, preventContentUpdate: true })
91
91
 
@@ -96,8 +96,9 @@ export const router = (
96
96
  })
97
97
  }
98
98
 
99
+ const hasSet = isInitial || (!isInitial && !isModal)
99
100
  if (hasSet) {
100
- if (options.forceContentUpdate || (!isInitial && wasModal)) {
101
+ if (options.forceContentUpdate || (!isInitial && wasModal && isModal)) {
101
102
  element.content.update()
102
103
  } else {
103
104
  element.set({
@@ -111,7 +112,7 @@ export const router = (
111
112
  }
112
113
  }
113
114
 
114
- if (!isModal && element.Modal.content) {
115
+ if (!isModal && element.Modal?.content) {
115
116
  element.Modal.removeContent()
116
117
  } else if (isModal && element.content?.Tabs) {
117
118
  element.content.Tabs.update()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbo.ls/router",
3
- "version": "2.12.65",
3
+ "version": "2.12.68",
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": "6590c42ef1d9670bc29e76efc22962abf4c49196",
14
+ "gitHead": "a9fc9f11d74aeb7c95403c9fe726e410ca9cb762",
15
15
  "source": "index.js"
16
16
  }