1.2.7 • Published 6 years ago

@nuento/mobx-react-router v1.2.7

Weekly downloads
45
License
MIT
Repository
github
Last release
6 years ago

mobx-react-router

Travis npm package Coveralls

A simple react router using mobx as state management

RouterStore

import RouterStore and add it the provider from mobx-react

import { Provider } from 'mobx-react';
import { RouterStore } from '@nuento/mobx-react-router';
import App from './App';

render(
  <Provider routerStore={new RouterStore()}>
    <App/>
  </Provider>,
  document.getElementById('root'),
);

Route

import { Route } from '@nuento/mobx-react-router';

<Route exact path="/" component={HomePage}/>
<Route path="/about" component={AboutPage}/>
<Route state-modal="signin" render={({match}) => {
  return <div>SignInModal</div>
}}/>
PropTypeDefault ValueDescription
pathstringnulldescribe a ExpressJS like path to match against.
exactboolfalserequire path to be an exact match
state-*string, numbernullmatch against specific key and value in the state.
renderfuncnullpass a function to be rendered on match
componentelementnullpass a react component to be rendered on match.

Link

import { Link } from '@nuento/mobx-react-router';

<Link to="/">Home</Link>
<Link replace to="/about">About</Link>
<Link tag="button" state-modal="signin">Sign In</Link>
PropTypeDefault ValueDescription
tostringnulldescribe a ExpressJS like path to match against.
state-*string, numbernullmatch against specific key and value in the state.
tagelementapass an element to act as the link component
replaceboolfalsereplace history instead of pushing

Switch

Only the first route match in the switch will be rendered, if nothing is matched the last element will be rendered.

import { Switch, Route } from '@nuento/mobx-react-router';

<Switch>
    <Route exact path="/" component={HomePage}/>
    <Route path="/about" component={AboutPage}/>
    <Route state-modal="signin" render={({match}) => {
      return <div>SignInModal</div>
    }}/>
</Switch>
PropTypeDefault ValueDescription
definedboolfalseset to true if you you dont want it to render last route if no match
1.2.7

6 years ago

1.2.6

6 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.9

7 years ago

1.1.8

7 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago