1.0.15 • Published 6 months ago

@gohanfromgoku/react-router-kit v1.0.15

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@gohanfromgoku/react-router-kit

  • Install the package

npm install @gohanfromgoku/react-router-kit
yarn add @gohanfromgoku/react-router-kit

  • Usage

// Navigation.tsx
import {OutletProvider, createRoutes} from "@gohanfromgoku/react-router-kit";
import About from "./pages/About";
import Home from "./pages/Home";
import User from "./pages/User";

const routes = createRoutes([
  {
    component: About,
    pathname: "/about",
  },
  {
    component: Home,
    pathname: "/",
  },
  {
    component: User,
    pathname: "/user/:id",
  },
]);


const Navigation = () => {
  return (
    <OutletProvider routes={routes}/> // you can add your own pageNotFound component
  );
};

export default Navigation;
//App.jsx

import React from "react";
import Navigation from "./Navigation";
import {navigate} from "@gohanfromgoku/react-router-kit";

const NavBtns = () => {
  return (
    <div>
        <button onClick={() => navigate("/")}>
          HOME
        </button>
        <button onClick={() => navigate("/about")}>
          About
        </button>
        <button onClick={() => navigate("/user/1234?name=1234")}>
          User
        </button>
    </div>
  );
};

const App = () => {
  return (
    <div>
      <h1>Hi</h1>
      <NavBtns />
      <Navigation/>
    </div>
  );
};

export default App;
 // User.tsx

 import {useLocation} from "@gohanfromgoku/react-router-kit";

const User = () => {
  const details = useLocationDetails();
  const params = useLocationParams();
  const queryParams = useLocationQueryParams();

  const extractedQueryParams = extractQueryParamsFromURL(details.href);
  // You can use window.location.href also instead of details.href.
  // This is same as useLocationQueryParams But you have to call manually every time, where useLocationQueryParams will auto get the values

  console.log(details, params, queryParams );
  return (
    <div>
          user
    </div>
  );
};

export default User;
1.0.15

6 months ago

1.0.14

6 months ago

1.0.13

6 months ago

1.0.12

6 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

0.0.7

8 months ago

1.0.0

8 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago