Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dmitrydivin/react-router-flux

Extension for react-router
https://github.com/dmitrydivin/react-router-flux

flux-architecture javascript react react-router

Last synced: about 1 month ago
JSON representation

Extension for react-router

Awesome Lists containing this project

README

        

Powerful extension for [react-router](https://github.com/ReactTraining/react-router) to declare routes.

### Installation

Using [npm](https://www.npmjs.com/):

```sh
$ npm install --save react-router-flux
```

And then you can import components as follows:

```javascript
// using an ES6 transpiler, like babel
import { Dispatcher, View, Action, Input } from 'react-router-flux';

// not using an ES6 transpiler
var Dispatcher = require('react-router-flux').Dispatcher;
var View = require('react-router-flux').View;
var Action = require('react-router-flux').Action;
var Input = require('react-router-flux').Input;
```

### Declare route dispatcher

```javascript

```

### Props
| Property | Type | Required | Description |
|:---------|:-------------|:---------|:------------------|
|component | `ReactClass` | yes | A React component |

### Declare view-state

The declaration can define in Dispatcher inside only

```javascript

```

### Props
| Property | Type | Required | Description |
|:---------|:--------|:---------|:--------------------|
|path | `String`| yes | Route path |

### Declare inbound parameter into view-state

The declaration can define in a View inside and in a Dispatcher too, but as default value and can be overridden.

```javascript

```

### Props
| Property | Type | Required | Description |
|:---------|:--------|:---------|:--------------------|
|name | `String`| yes | Input property name |
|value | `Any` | no | Input property value|

> **Note**: If the value define as Function you can access to route variables 'params', 'query' and 'state', see below example.

### Declare transition

The declaration can define in Dispatcher inside only

```javascript

```

### Props
| Property | Type | Required | Description |
|:---------|:-----------------------|:---------|:-----------------------------------------|
|on | `String` | yes | Event ID of the component |
|to | `String` | yes | Redirect Route path |
|query | `Function` or `Object` | no | Define query params for the Route path |
|state | `Function` or `Object` | no | Define route state for the Router |
|params | `Function` or `Object` | no | Define params for the Route path |

### How Does It Use?

```javascript
class TodoMVC extends React.Component {
render() {
let {
filter, /** filter parameter **/
onFilter, /** to go to /todomvc/active when onFilter({filter: 'active'}) **/
onFilterNotFound /** to go to /error/404 **/
} = this.props;
//...
}
};

//store filter variable as path parameter
// `/todomvc` ->
// `/todomvc/active` ->
const mapping_v1 = (


{/*as default value*/}



params.filter}/>


{ return {filter} }}/>



);

//store filter variable as path parameter v_2
// `/todomvc` ->
// `/todomvc/active` ->
const mapping_v2 = (














{ return {filter} }}/>


);

//store filter variable as query parameter
// `/todomvc` ->
// `/todomvc?filter=active` ->
const mapping_v3 = (


{/*as default value*/}



query.filter}/>


{ return {filter} }}/>



);

```

### License

MIT, © 2017 Dmitry Divin.