An open API service indexing awesome lists of open source software.

https://github.com/avraammavridis/react-mini-router-hook

Mini Router for React, change route using hook
https://github.com/avraammavridis/react-mini-router-hook

Last synced: 6 months ago
JSON representation

Mini Router for React, change route using hook

Awesome Lists containing this project

README

          

# react-mini-router-hook

Mini Router for React based on Hooks and Context. 1.7k

### Declare your Routes

```js
import { Router, Route } from "react-mini-router-hook";

export default function App() {
return (



);
}
```

### Change route from a component

```js
import { RouterContext } from 'react-mini-router-hook';

export default function NavBar() {
const { setPath } = React.useContext(RouterContext);

return (


  • setPath('/users/1')}>Menu Item 1

  • setPath('/users/2')}>Menu Item 1

    • );
      }
      ```

      ### Get current path

      ```js
      import { RouterContext } from 'react-mini-router-hook';

      export default function Helmet() {
      const { path } = React.useContext(RouterContext);

      return ({path});
      }
      ```