Home

Awesome

<p align="center"> <a href="https://github.com/ri7nz/react-router-ext/compare"><img src="https://img.shields.io/badge/PRs-welcome-green.svg" alt="PRS Welcome"></a> <a href="https://www.npmjs.org/package/react-router-ext"><img src="https://img.shields.io/npm/v/react-router-ext.svg" alt="npm"></a> <a href="https://bundlephobia.com/result?p=react-router-ext"><img src="https://badgen.net/bundlephobia/minzip/react-router-ext" alt="bundlephobia"></a> <a href="https://snyk.io/test/github/ri7nz/react-router-ext"><img src="https://snyk.io/test/github/ri7nz/react-router-ext/badge.svg" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/ri7nz/react-router-ext" style="max-width:100%;"></a> </p>

⚛️ react-router-ext.

An Extended react-router-dom with Simple Usage for ReactJs.

Table of Contents

Install

yarn

yarn add react-router-ext

npm

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>

Usage

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')
)

API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

Parameters

Properties

Examples

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

Route

Type: Object

Properties

Credits