1.0.15 • Published 1 year ago
@gohanfromgoku/react-router-kit v1.0.15
@gohanfromgoku/react-router-kit
Install the package
npm install @gohanfromgoku/react-router-kityarn add @gohanfromgoku/react-router-kitUsage
// 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
1 year ago
1.0.14
1 year ago
1.0.13
1 year ago
1.0.12
1 year ago
1.0.11
1 year ago
1.0.10
1 year ago
1.0.9
1 year ago
1.0.8
1 year ago
1.0.7
1 year ago
1.0.6
1 year ago
1.0.5
1 year ago
1.0.4
1 year ago
1.0.3
1 year ago
0.0.7
1 year ago
1.0.0
1 year ago
0.0.6
1 year ago
0.0.5
1 year ago
0.0.4
1 year ago
0.0.3
1 year ago
0.0.2
1 year ago