npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-acl-router

v1.0.0

Published

Router with Access Control for React Applications.

Downloads

75

Readme

react-acl-router

npm v npm dm

Router with Access Control for React Applications.

Installation

yarn add react-acl-router react react-router-dom lodash

Usage

AclRouter

| Property | Description | Type | Default | | ------------------ | ---------------------------------------------- | -------------------------------- | ----------------------------- | | authorities | permissions of current user | OneOfType([string, array, func]) | '' | | authorizedRoutes | array of routes needs permissions | arrayOf(AuthorizedRoute) | [] | | authorizedLayout | container of all authorized routes | function | <div>{props.children}</div> | | normalRoutes | array of routes don't need permissions | arrayOf(NormalRoute) | [] | | normalLayout | container of all routes don't need permissions | function | <div>{props.children}</div> | | notFound | element to show when route doesn't match | function | <div>404</div> |

AuthorizedRoute

with all react-router <Route /> supported props except render because react-acl-router will overwrite the render prop.

| Property | Description | Type | Default | | ------------ | ---------------------------------------------------------------- | --------------- | -------- | | path | route's full path | string | - | | permissions | array of roles which have permission like ['god', 'admin' ] | arrayOf(string) | - | | component | route's component | function | - | | unauthorized | unauthorized view component if authorities don't have permission | string | - | | redirect | redirect path if authorities don't have permission | string | - |

NormalRoute (with react-router Route's all supported props)

with all react-router <Route /> supported props except render because react-acl-router will overwrite the render prop.

| Property | Description | Type | Default | | ----------- | ---------------------------------- | --------------- | -------- | | path | route's full path | string | - | | redirect | redirect route path to other route | string | - | | component | route's component | function | - |

Example

import AclRouter from 'react-acl-router';
import BasicLayout from 'layouts/BasicLayout';
import NormalLayout from 'layouts/NormalLayout';
import Login from 'views/login';
import WorkInProgress from 'views/workInProgress';
import Unauthorized from 'views/unauthorized';

const authorizedRoutes = [{
  path: '/dashboard/analysis/realtime',
  exact: true,
  permissions: ['admin', 'user'],
  redirect: '/login',
  component: WorkInProgress,
}, {
  path: '/dashboard/analysis/offline',
  exact: true,
  permissions: ['admin', 'user'],
  redirect: '/login',
  component: WorkInProgress,
}, {
  path: '/dashboard/workplace',
  exact: true,
  permissions: ['admin', 'user'],
  redirect: '/login',
  component: WorkInProgress,
}, {
  path: '/exception/403',
  exact: true,
  permissions: ['god'],
  component: WorkInProgress,
  unauthorized: Unauthorized,
}];

const normalRoutes = [{
  path: '/',
  exact: true,
  redirect: '/dashboard/analysis/realtime',
}, {
  path: '/login',
  exact: true,
  component: Login,
}];

const Router = (props) => (
  <AclRouter
    // sync user authorities with the user data in your application
    authorities={props.user.authorities}
    authorizedRoutes={authorizedRoutes}
    authorizedLayout={BasicLayout}
    normalRoutes={unAuthorizedRoutes}
    normalLayout={NormalLayout}
    notFound={() => <div>Page Not Found</div>}
  />
);

export default Router;

Notes

  • For normal route, redirect or unauthorized and component are exclusive since normally you won't redirect user to another path while you have a valid component to render.