Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/razorrsd/md-react-router

A Simple react router light weight and easy to use
https://github.com/razorrsd/md-react-router

react react-router reactjs reactjs-components router simple typescript

Last synced: 13 days ago
JSON representation

A Simple react router light weight and easy to use

Awesome Lists containing this project

README

        

# md-react-router

A simple, lightweight, and easy-to-use react-router. Just add your routes list you are good to go.

## Install

```bash
npm install --save md-react-router
```

## Usage

_Add your routes list in `routes.js` file_

```ts
import { Home, About, TestHash, ItemCategories, Item } from './pages'

export const routes = [
{
path: '/',
children:
},
{
path: '/about',
children:
},
//Use Hash to redirect: page will be desided on letters and you can pass a id using numbers after letters
{
hash: 'ct',
children:
},
//You can add Dynamic Routing with ":" name
{
path: '/testDyn/:catid',
children:
},
{
path: '/testDyn/:id/details',
children:
}
]
```

_Add `Router` component in your `App.js` file_

```tsx
import React from 'react'
import { Router } from 'md-react-router'
import Header from './components/header'
import NotFound from './componets/NotFoundComp'
import Routes from './Routes'

const App = () => {
return (



{getRoutes(Routes, NotFound)}


)
}

export default App
```

_Use "Link" instead of "A" when you want to navigate to another page_

```tsx
import React from 'react'
import { Link } from 'md-react-router'

const Header = () => {
return (


Home
About
Contact
Test Hash
Category 01
Item X

)
}

export default Header
```

_You can ust ctx to get query values from router_

```tsx
import React from 'react'
import { ctx } from 'md-react-router'

const Item = () => {
return

testDyn {ctx.query.id}

}

export default Item
```

## License

MIT © [RazorRSD](https://github.com/RazorRSD)