An Extended react-router-dom with Simple Usage for ReactJs.
yarn add react-router-ext
npm install --save react-router-ext
The UMD build is also available on unpkg:
<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
Objectconst 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> RouteRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4