@discovery-solutions/react-router
v0.0.2
Published
A simplified lightweight router for ReactJS and React Native
Downloads
2
Readme
@discovery-solutions/react-router
Uma biblioteca leve e simples de roteamento para ReactJS e React Native
npm i @discovery-solutions/react-router
Conteúdo
Utilização Padrão
A API de utilização é parecida com o react-router-dom
, ficando assim:
App.js
import React from "react";
import {
RouterProvider,
Redirect,
Route,
} from "@discovery-solutions/react-router";
import Home from "./Home";
import About from "./About";
const App = () => {
return (
<RouterProvider>
<Route path="/" component={ Home } exact/>
<Route path="/about" component={ About } exact/>
<Redirect from="*" to="/" />
</RouterProvider>
)
}
Home.js
import React from "react";
import { Link } from "@discovery-solutions/react-router";
const Home = () => (
<>
<Link link="/about">Funciona com "link"</Link>
<Link href="/about">Também funciona com "href"</Link>
<Link to="/about">E até com "to"</Link>
</>
)
About.js
import React from "react";
import { redirect } from "@discovery-solutions/react-router";
const About = () => (
<button onClick={ redirect("/", { something: "some value" }) }>E tem como redirecionar via função</button>
)