router-kit 0.2.1 → 0.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.
|
@@ -7,19 +7,27 @@ const RouterProvider = ({ routes }) => {
|
|
|
7
7
|
const [path, setPath] = useState(window.location.pathname);
|
|
8
8
|
let fullPathWithParams = "";
|
|
9
9
|
const pathValidation = (routeFullPath, currentPath) => {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const r = routeParts[i];
|
|
16
|
-
const p = pathParts[i];
|
|
17
|
-
if (r.startsWith(":"))
|
|
10
|
+
const routePaths = routeFullPath.split("|");
|
|
11
|
+
for (const routePath of routePaths) {
|
|
12
|
+
const routeParts = routePath.split("/").filter(Boolean);
|
|
13
|
+
const pathParts = currentPath.split("/").filter(Boolean);
|
|
14
|
+
if (routeParts.length !== pathParts.length)
|
|
18
15
|
continue;
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
let isMatch = true;
|
|
17
|
+
for (let i = 0; i < routeParts.length; i++) {
|
|
18
|
+
const r = routeParts[i];
|
|
19
|
+
const p = pathParts[i];
|
|
20
|
+
if (r.startsWith(":"))
|
|
21
|
+
continue;
|
|
22
|
+
if (r !== p) {
|
|
23
|
+
isMatch = false;
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (isMatch)
|
|
28
|
+
return true;
|
|
21
29
|
}
|
|
22
|
-
return
|
|
30
|
+
return false;
|
|
23
31
|
};
|
|
24
32
|
const getComponent = (routesList, currentPath, parentPath = "/") => {
|
|
25
33
|
for (const route of routesList) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
function normalizeRoutes(inputRoutes) {
|
|
2
2
|
return inputRoutes.map((route) => {
|
|
3
|
-
|
|
4
|
-
const normalizedPath =
|
|
5
|
-
?
|
|
6
|
-
|
|
3
|
+
const pathArray = Array.isArray(route.path) ? route.path : [route.path];
|
|
4
|
+
const normalizedPath = pathArray
|
|
5
|
+
.map((path) => (path === null || path === void 0 ? void 0 : path.startsWith("/")) ? path.replace(/^\/+/, "") : path !== null && path !== void 0 ? path : "")
|
|
6
|
+
.join("|");
|
|
7
7
|
const normalized = {
|
|
8
8
|
...route,
|
|
9
9
|
path: normalizedPath,
|
package/package.json
CHANGED