1.0.13 ā€¢ Published 4 years ago

react-mega-router v1.0.13

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

šŸ›£šŸ›£ React Mega Router šŸ›£šŸ›£

Yet another React router. But this one has multi-columns, hooks and animations, built-in.

Features

āœ… Multi-columns, aka nested side-by-side routes (cols prop) \ āœ… Enter hook (onEnter prop or onEnter route attribute) \ āœ… Leave async blockable hook (onLeave prop or onLeave route attribute) \ āœ… Browser, Hash or Memory history (memory, hash and historyParams props) \ āœ… Animation classNames: will-enter, entering, direction-forward, direction-backward, direction-same, col-1, col-2, cols-2, ... \ āœ… Link component with automatic active className

Demo

šŸ‘€ Try it\ šŸ›  Grill it šŸ”Ø

Install

Via NPM:

npm install react-mega-router --save

Via Yarn:

yarn add react-mega-router

Basic Usage

import Router from 'react-mega-router';
import { PageFoo, PageBar, PageMoien } from './pages';

const demoRoutes = [
   {
      path: '/foo',
      component: PageFoo,
      onEnter: (route, history, action) => console.log('Just entered!'),
      onLeave: (route, history) => console.log('Should I block the navigation?'),
      onMount: params => console.log('mounted!', params),
      routes: [
         {
            path: '/foo/:bar',
            component: PageBar
         }
      ]
   },
   {
      path: '/moien',
      component: PageMoien
   }
];

const App = props => {
   return <Router routes={demoRoutes} cols={2} />;
};

Router props

PropertyTypeRequiredDescription
routesarraytrueArray of Route (details below)
colsintegerfalseNumber of visible columns
onEnterfunctionfalseTriggered by (any) route entering (route, history, actionlocation, action, )=>{}
onLeavefunctionfalseTriggered by (any) route leaving async (route, history)=>{}, returns false to deny navigation
onMountfunctionfalseTriggered when component is ready
animatebooleanfalseFalse to disable animation classNames
pathstringfalseForced router path, ignoring history
notFoundreact elementfalseNot found route fallback
memorybooleanfalseuse memoryHistory instead of browserHistory
hashbooleanfalseuse hashHistory instead of browserHistory
historyParamsobjectfalsepass params to createHistory

Route attributes

PropertyTypeRequiredDescription
pathstringtruepath (url-pattern format)
componentReact ComponenttrueNumber of visible columns
routesarrayfalseSub routes
onEnterfunctionfalseTriggered by route entering
onLeavefunctionfalseTriggered by route leaving async (route, history)=>{}, returns false to block navigation
animationstringfalseAnimation className, false to disabled
{...}-falseAny other props that needs to be passed to component

Route component passed props

PropertyTypeDescription
historyhistoryHistory object
colintegerCurrent column
colsintegerColumns count
pathstringCurrent path
routerobjectRouter props
{...}-Any other route attributes

Advanced Usage: external navigation Links

The history can be externalized using HistoryProvider. \ This can be useful to use Link components outside of the Router:

import Router, { HistoryProvider, Link } from 'react-mega-router';

//const demoRoutes = ...

const App = props => {
   return (
      <HistoryProvider>
         <Router routes={demoRoutes} cols={2} />
         <nav>
            <Link href="/route1">Route 1</Link>
            <Link href="/route1/foobar">Route 1 sub</Link>
         </nav>
      </HistoryProvider>
   );
};
1.0.13

4 years ago

1.0.11

4 years ago

1.0.12

4 years ago

1.0.9

4 years ago

1.0.10

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.5-0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago