Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-rolebased-router

LeulAria69MIT2.1.0TypeScript support: included

A simple, easy and intuitive way of creating routes for react using react router dom.

react, router, react-dom, rolebased, role based, router dom, react-router, router config, react routing, react-router-dom, rolebased router, role based router, react router auth, react easy routing, react router config, simple react router, react router config, rolebased react router, react role auth router, react-router-dom-config, role based react router, react router typescript, typescript router react, react router easy config, role based routing react, react routing with auth role, react router config with auth role, react router rolebased react router

readme

react rolebased router

package size npm version downloads per month

Usage


npm i react-rolebased-router

yarn add react-rolebased-router

Here is a quick example to get you started, it's all you need:

import * as React from 'react';
import ReactDOM from 'react-dom';

import { BrowserRouter } from "react-router-dom";
import ReactRoleAccessRouter from "react-rolebased-router";
import { RouterConfig } from "react-rolebased-router/lib/types";

const routes: RouterConfig[] = [
  {
    path: "/",
    exact: true,
    redirect: [
      {
        page: "/dashboard",
        permissions: ["admin"],
      }
    ],
    exact: true,
    fallback: <div>Loading...</div>,
  },
  {
    path: "/home",
    component: lazy(() => import("./pages/Home")),
    exact: true,
    fallback: <div>Loading...</div>,
    private: true,
    permissions: ["super-admin", "admin"]
  },
  ...
  {
    path: "/*",
    component: lazy(() => import("./pages/NotFound")),
    exact: false,
    fallback: <div>Loading...</div>,
    routeParam: {
      title: "Page Not Found",
      component: <h1>Test Parameter</h1>
    }
  },
  {
    path: "/*",
    component: lazy(() => import("./pages/NotFound")),
    exact: false,
    fallback: <div>Loading...</div>,
    routes: [
      {
        path: "/*",
        component: lazy(() => import("./pages/NotFound")),
        exact: false,
        fallback: <div>Loading...</div>,
      },
    ]
  },
]

const App = () => {
  return (
    </BrowserRouter>
      <ReactRoleAccessRouter
        routes={routes}
        userAuthRoles={userRoles}
        loginRedirectPath={"/login"}
        isUserAuthenticated={loggedIn}
      />
    </BrowserRouter>
  )
}

ReactDOM.render(<App />, document.querySelector('#app'));

See Demo:

Edit Button

🤔 Wana make it awesome, contribute, create an issue and more are welcome.

2021.