An Extended react-router-dom with Simple Usage for ReactJs.
- Just Pass Props & Render All your Component Page.
- With Sub Route Routes -> Routes -> Routes .... -> Routes.
- Have an options for Wrapper.
yarn add react-router-ext
npm install --save react-router-ext
<script src="https://unpkg.com/react-router-ext@latest/dist/react-router-ext.umd.js"></script>
An Example usage react-router-ext.
import React from 'react'
import ReactDOM from 'react-dom'
import MainRouter from 'react-router-ext'
/** Example AuthHOC **/
const AuthHOC = (AuthLogic) => (Component) => AuthLogic()
? <Component>
: <div> Not Authorized </div>
/** Component Pages **/
const Home = () => <div> Welcome in my home 🈴 </div>
const BedRoom = () => <div> My BedRoom is Private ❌ </div>
const Room = () => <div> Happy </div>
/** Config route list in Array **/
const routeList = [
{
path: '/',
component: Home,
exact: true
},
{
path: '/room',
component: Room,
exact: true,
routes: [
{
path: '/bedroom',
component: BedRoom,
wrapper: AuthHOC(() => false)
}
]
}
]
// Render
ReactDOM.render(
<MainRouter routes={routeList} />,
document.getElementById('app')
)
props
Object
const routeList = [
// Basic
{
path: '/',
component: Home,
exact: true,
},
// With Wrapper Component
{
path: '/',
component: Home,
exact: true,
wrapper: AuthComponent,
},
// With Routes
{
path: '/',
component: Home,
exact: true,
wrapper: AuthComponent,
routes: [
{
path: '/article',
component: Article,
exact: true,
routes: [
{
path: '/categories',
component: Category,
},
]
},
]
}
]
// Render
ReactDOM.render(<MainRoute routes={routeList}/>, node)
Returns ReactElement
Type: Object
path
String Path-stingexact
Boolean Exact-boolcomponent
Object Componentwrapper
Function A Wrapper function for componentroutes
Array<Route> Route
- MIT License © 2019 ri7nz
- See: reactjs for use this Project.
- See: react-router-dom The main idea & goals.
- See: Microbundle 🔨 for bundle this Project.