router-kit 1.2.0 → 1.2.2
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.
|
@@ -18,16 +18,28 @@ const RouterProvider = ({ routes }) => {
|
|
|
18
18
|
let page404 = null;
|
|
19
19
|
useEffect(() => {
|
|
20
20
|
setPath(window.location.pathname);
|
|
21
|
+
const patchHistory = (method) => {
|
|
22
|
+
const original = window.history[method];
|
|
23
|
+
return function (state, title, url) {
|
|
24
|
+
const result = original.apply(this, [state, title, url]);
|
|
25
|
+
window.dispatchEvent(new Event("locationchange"));
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const originalPush = window.history.pushState;
|
|
30
|
+
const originalReplace = window.history.replaceState;
|
|
31
|
+
window.history.pushState = patchHistory("pushState");
|
|
32
|
+
window.history.replaceState = patchHistory("replaceState");
|
|
21
33
|
const handleLocationChange = () => {
|
|
22
34
|
setPath(window.location.pathname);
|
|
23
35
|
};
|
|
24
36
|
window.addEventListener("popstate", handleLocationChange);
|
|
25
|
-
window.addEventListener("
|
|
26
|
-
window.addEventListener("replaceState", handleLocationChange);
|
|
37
|
+
window.addEventListener("locationchange", handleLocationChange);
|
|
27
38
|
return () => {
|
|
39
|
+
window.history.pushState = originalPush;
|
|
40
|
+
window.history.replaceState = originalReplace;
|
|
28
41
|
window.removeEventListener("popstate", handleLocationChange);
|
|
29
|
-
window.removeEventListener("
|
|
30
|
-
window.removeEventListener("replaceState", handleLocationChange);
|
|
42
|
+
window.removeEventListener("locationchange", handleLocationChange);
|
|
31
43
|
};
|
|
32
44
|
}, []);
|
|
33
45
|
const pathValidation = (routeFullPath, currentPath) => {
|
|
@@ -76,6 +88,9 @@ const RouterProvider = ({ routes }) => {
|
|
|
76
88
|
return null;
|
|
77
89
|
};
|
|
78
90
|
const navigate = (to, options) => {
|
|
91
|
+
if (!/^https?:\/\//i.test(to)) {
|
|
92
|
+
to = to.startsWith("/") ? to : `/${to}`;
|
|
93
|
+
}
|
|
79
94
|
if (!validateUrl(to)) {
|
|
80
95
|
console.error(`RouterKit: Invalid URL "${to}"`);
|
|
81
96
|
return;
|
package/dist/hooks/useRouter.js
CHANGED
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Router-Kit — Common hooks and components (reference)
|
|
3
|
-
|
|
4
|
-
Hooks:
|
|
5
|
-
- useRouter : access router context and helpers
|
|
6
|
-
- useLocation : current location (pathname, search, hash)
|
|
7
|
-
- useNavigate : imperative navigation function
|
|
8
|
-
- useParams : route params for the current route
|
|
9
|
-
- useSearchParams : read/update URL query params
|
|
10
|
-
- useRouteMatch : match the current location against a pattern
|
|
11
|
-
- useBlocker/usePrompt : block navigation with a confirmation
|
|
12
|
-
|
|
13
|
-
Components / APIs:
|
|
14
|
-
- createRouter : factory to create a router instance and Provider
|
|
15
|
-
- RouterProvider : provider component returned by createRouter()
|
|
16
|
-
- Routes : route collection wrapper
|
|
17
|
-
- Route : single route declaration
|
|
18
|
-
- Link : declarative link component
|
|
19
|
-
- NavLink : link with active styling
|
|
20
|
-
- Outlet : render child route content
|
|
21
|
-
- Redirect : declarative redirect helper (if provided)
|
|
22
|
-
|
|
23
|
-
Note: Exact names may vary between versions — update this list to match your installed Router-Kit exports.
|
|
24
|
-
*/
|
|
25
1
|
import { useContext } from "react";
|
|
26
2
|
import RouterContext from "../context/RouterContext";
|
|
27
3
|
export function useRouter() {
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"email": "mohammed.bencheikh.dev@gmail.com",
|
|
6
6
|
"url": "https://mohammedbencheikh.com/"
|
|
7
7
|
},
|
|
8
|
-
"version": "1.2.
|
|
8
|
+
"version": "1.2.2",
|
|
9
9
|
"description": "A small React routing provider library",
|
|
10
10
|
"main": "dist/index.js",
|
|
11
11
|
"types": "dist/index.d.ts",
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
"pack:verify": "npm pack --dry-run",
|
|
22
22
|
"audit": "npm audit",
|
|
23
23
|
"audit:fix": "npm audit fix",
|
|
24
|
-
"preinstall": "npx npm-force-resolutions",
|
|
25
24
|
"validate:deps": "npm ls"
|
|
26
25
|
},
|
|
27
26
|
"peerDependencies": {
|
|
@@ -33,12 +32,11 @@
|
|
|
33
32
|
},
|
|
34
33
|
"devDependencies": {
|
|
35
34
|
"typescript": "^5.2.0",
|
|
36
|
-
"@types/react": "^
|
|
37
|
-
"@types/react-dom": "^
|
|
38
|
-
"@types/url-join": "^
|
|
39
|
-
"npm-force-resolutions": "^0.0.10"
|
|
35
|
+
"@types/react": "^19.2.2",
|
|
36
|
+
"@types/react-dom": "^19.2.2",
|
|
37
|
+
"@types/url-join": "^5.0.0"
|
|
40
38
|
},
|
|
41
|
-
"
|
|
39
|
+
"overrides": {
|
|
42
40
|
"minimist": "^1.2.6",
|
|
43
41
|
"node-fetch": "^2.6.7"
|
|
44
42
|
},
|