@unsetsoft/ryunixjs 0.4.13-nightly.47 → 0.4.13-nightly.48

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/dist/Ryunix.js CHANGED
@@ -274,7 +274,7 @@
274
274
  return hook.query
275
275
  };
276
276
 
277
- const Router = ({ path, component }) => {
277
+ const Router = ({ path, component, children }) => {
278
278
  const [currentPath, setCurrentPath] = useStore(window.location.pathname);
279
279
 
280
280
  useEffect(() => {
@@ -282,18 +282,16 @@
282
282
  setCurrentPath(() => window.location.pathname);
283
283
  };
284
284
 
285
- window.addEventListener('navigate', onLocationChange);
286
- window.addEventListener('pushsatate', onLocationChange);
287
285
  window.addEventListener('popstate', onLocationChange);
288
286
 
289
287
  return () => {
290
- window.removeEventListener('navigate', onLocationChange);
291
- window.removeEventListener('pushsatate', onLocationChange);
292
288
  window.removeEventListener('popstate', onLocationChange);
293
289
  }
294
290
  }, [currentPath]);
295
291
 
296
- return currentPath === path ? component() : null
292
+ const Children = children ? children : component();
293
+
294
+ return currentPath === path ? Children : null
297
295
  };
298
296
 
299
297
  const Navigate = () => {
@@ -311,8 +309,9 @@
311
309
  */
312
310
  const push = (to, state = {}) => {
313
311
  if (window.location.pathname === to) return
312
+
314
313
  window.history.pushState(state, '', to);
315
- const navigationEvent = new Event('pushsatate');
314
+ const navigationEvent = new PopStateEvent('popstate');
316
315
  window.dispatchEvent(navigationEvent);
317
316
  };
318
317
 
@@ -339,6 +338,10 @@
339
338
  throw new Error("Missig 'to' param.")
340
339
  }
341
340
  const preventReload = (event) => {
341
+ if (event.metaKey || event.ctrlKey) {
342
+ return
343
+ }
344
+
342
345
  event.preventDefault();
343
346
  const { push } = Navigate();
344
347
  push(props.to);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unsetsoft/ryunixjs",
3
- "version": "0.4.13-nightly.47",
3
+ "version": "0.4.13-nightly.48",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.js",
6
6
  "types": "./dist/Ryunix.d.ts",
@@ -1,6 +1,6 @@
1
1
  import { useStore, useEffect } from './hooks'
2
2
  import { createElement } from './createElement'
3
- const Router = ({ path, component }) => {
3
+ const Router = ({ path, component, children }) => {
4
4
  const [currentPath, setCurrentPath] = useStore(window.location.pathname)
5
5
 
6
6
  useEffect(() => {
@@ -8,18 +8,16 @@ const Router = ({ path, component }) => {
8
8
  setCurrentPath(() => window.location.pathname)
9
9
  }
10
10
 
11
- window.addEventListener('navigate', onLocationChange)
12
- window.addEventListener('pushsatate', onLocationChange)
13
11
  window.addEventListener('popstate', onLocationChange)
14
12
 
15
13
  return () => {
16
- window.removeEventListener('navigate', onLocationChange)
17
- window.removeEventListener('pushsatate', onLocationChange)
18
14
  window.removeEventListener('popstate', onLocationChange)
19
15
  }
20
16
  }, [currentPath])
21
17
 
22
- return currentPath === path ? component() : null
18
+ const Children = children ? children : component()
19
+
20
+ return currentPath === path ? Children : null
23
21
  }
24
22
 
25
23
  const Navigate = () => {
@@ -37,8 +35,9 @@ const Navigate = () => {
37
35
  */
38
36
  const push = (to, state = {}) => {
39
37
  if (window.location.pathname === to) return
38
+
40
39
  window.history.pushState(state, '', to)
41
- const navigationEvent = new Event('pushsatate')
40
+ const navigationEvent = new PopStateEvent('popstate')
42
41
  window.dispatchEvent(navigationEvent)
43
42
  }
44
43
 
@@ -65,6 +64,10 @@ const Link = (props) => {
65
64
  throw new Error("Missig 'to' param.")
66
65
  }
67
66
  const preventReload = (event) => {
67
+ if (event.metaKey || event.ctrlKey) {
68
+ return
69
+ }
70
+
68
71
  event.preventDefault()
69
72
  const { push } = Navigate()
70
73
  push(props.to)