router-kit 0.1.7 → 0.2.0

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.
@@ -1,2 +1,5 @@
1
- declare const RouterProvider: () => import("react/jsx-runtime").JSX.Element;
1
+ import type { Route } from "../types";
2
+ declare const RouterProvider: ({ routes }: {
3
+ routes: Route[];
4
+ }) => import("react/jsx-runtime").JSX.Element;
2
5
  export default RouterProvider;
@@ -1,10 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useEffect, useState } from "react";
3
3
  import join from "url-join";
4
- import { routes } from "../core/createRouter";
5
4
  import Page404 from "../pages/404";
6
5
  import RouterContext from "./RouterContext";
7
- const RouterProvider = () => {
6
+ const RouterProvider = ({ routes }) => {
8
7
  const [path, setPath] = useState(window.location.pathname);
9
8
  let fullPathWithParams = "";
10
9
  const pathValidation = (routeFullPath, currentPath) => {
@@ -1,4 +1,3 @@
1
1
  import type { Route } from "../types";
2
2
  declare function createRouter(inputRoutes: Route[]): Route[];
3
- export declare const routes: Route[];
4
3
  export default createRouter;
@@ -1,5 +1,5 @@
1
1
  function normalizeRoutes(inputRoutes) {
2
- const normalizedRoutes = inputRoutes.map((route) => {
2
+ return inputRoutes.map((route) => {
3
3
  var _a, _b;
4
4
  const normalizedPath = ((_a = route.path) === null || _a === void 0 ? void 0 : _a.startsWith("/"))
5
5
  ? route.path.replace(/^\/+/, "")
@@ -13,13 +13,8 @@ function normalizeRoutes(inputRoutes) {
13
13
  }
14
14
  return normalized;
15
15
  });
16
- routes.length = 0;
17
- routes.push(...normalizedRoutes);
18
- return routes;
19
16
  }
20
17
  function createRouter(inputRoutes) {
21
- // normalize and mutate the exported `routes` array in-place
22
18
  return normalizeRoutes(inputRoutes);
23
19
  }
24
- export const routes = [];
25
20
  export default createRouter;
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": "0.1.7",
8
+ "version": "0.2.0",
9
9
  "description": "A small React routing provider library",
10
10
  "main": "dist/index.js",
11
11
  "types": "dist/index.d.ts",