@unsetsoft/ryunixjs 0.2.30-nightly.1 → 0.2.30-nightly.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.
- package/package.json +1 -1
- package/src/lib/index.js +2 -2
- package/src/lib/navigation.js +16 -7
- package/src/main.js +2 -0
package/package.json
CHANGED
package/src/lib/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createElement, Fragments } from "./createElement";
|
|
|
2
2
|
import { render, init } from "./render";
|
|
3
3
|
import { useContext, useStore, useEffect } from "./hooks";
|
|
4
4
|
import { createContext } from "./createContext";
|
|
5
|
-
import { Router,
|
|
5
|
+
import { Router, Navigate } from "./navigation";
|
|
6
6
|
import * as Dom from "./dom";
|
|
7
7
|
import * as Workers from "./workers";
|
|
8
8
|
import * as Reconciler from "./reconciler";
|
|
@@ -16,7 +16,7 @@ export {
|
|
|
16
16
|
useContext,
|
|
17
17
|
Fragments,
|
|
18
18
|
Router,
|
|
19
|
-
|
|
19
|
+
Navigate,
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
export default {
|
package/src/lib/navigation.js
CHANGED
|
@@ -22,7 +22,18 @@ const Router = ({ path, component }) => {
|
|
|
22
22
|
return currentPath === path ? component() : null;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
const
|
|
25
|
+
const Navigate = (props) => {
|
|
26
|
+
if (props.style) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
"The style attribute is not supported on internal components."
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
if (props.to === "") {
|
|
32
|
+
throw new Error("'to=' cannot be empty.");
|
|
33
|
+
}
|
|
34
|
+
if (props.className === "") {
|
|
35
|
+
throw new Error("className cannot be empty.");
|
|
36
|
+
}
|
|
26
37
|
const preventReload = (event) => {
|
|
27
38
|
event.preventDefault();
|
|
28
39
|
if (window.location.pathname !== props.to) {
|
|
@@ -32,11 +43,9 @@ const Link = (props) => {
|
|
|
32
43
|
localStorage.setItem("pathname", props.to);
|
|
33
44
|
}
|
|
34
45
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
props.children
|
|
39
|
-
);
|
|
46
|
+
|
|
47
|
+
const anchor = { href: props.to, onClick: preventReload, ...props };
|
|
48
|
+
return createElement("a", anchor, props.label);
|
|
40
49
|
};
|
|
41
50
|
|
|
42
|
-
export { Router,
|
|
51
|
+
export { Router, Navigate };
|