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

https://github.com/metalabdesign/waygate

Routing experiment cause that's hot right now.
https://github.com/metalabdesign/waygate

bootstart react react-router redux

Last synced: about 2 months ago
JSON representation

Routing experiment cause that's hot right now.

Awesome Lists containing this project

README

          

# waygate

You probably want [react-router] instead.

![build status](http://img.shields.io/travis/metalabdesign/waygate/master.svg?style=flat)
![coverage](https://img.shields.io/codecov/c/github/metalabdesign/waygate/master.svg?style=flat)
![license](http://img.shields.io/npm/l/waygate.svg?style=flat)
![version](http://img.shields.io/npm/v/waygate.svg?style=flat)
![downloads](http://img.shields.io/npm/dm/waygate.svg?style=flat)

Leveraging `redux` to power your react routing needs. The API very closely resembles [react-router] because familiarity is good and I personally like the declarative syntax. This exists mostly as an experiment to have _all_ the routing state controlled by `redux`. For people who lean more towards the purist side of functional programming this may be appealing. Works with [react-hot-loader] too.

## Usage

```js
import React from 'react';
import {Provider} from 'react-redux';
import {Match, Switch, navigate} from 'waygate';

// Create a `Link` component for your app.
const Link = connect(null, {navigate})(({navigate, to, ...rest}) => (
{
ev.preventDefault();
navigate(to);
}}
{...rest}
/>
));

// Create a navigation tree.
const App = ({store}) => (




Foo

Go to /bar




Bar




);

export default App;
```

### web

Connect `waygate` to the HTML5 history API:

```js
import {createStore as baseCreateStore, applyMiddleware} from 'redux';
import {createMiddleware as waygate} from 'waygate';
import reducer from '...';

const createStore = (initialState) => {
const middleware = applyMiddleware(
waygate(),
);
return baseCreateStore(reducer, initialState, middleware);
};

export default createStore;
```

### node

Manually dispatch `navigate()` actions.

```js
import ReactDOMServer from 'react-dom/server';
import {navigate} from 'waygate';
import createStore from '...';
import App from '...';

const render = (path) => {
const store = createStore();
store.dispatch(navigate(path));
return ReactDOMServer.renderToString(

);
};

export default render;
```

## API

### Switch

Render the first match-compatible component in a list of children. Switch does not render child `Match` nodes in the react tree – only their children. This allows you to perform animations and transitions with tools like `react-motion`.

```js
const willLeave = () => ({opacity: 0});

const styles = (children) => React.Children.map(children, (child) => {
return {
key: child.key,
style: {opacity: 1},
data: child,
}
});

const Transition = ({children}) => (
{


{styles.map(({style: {opacity}, data: child, key}) => (

{child}

))}

}}
/>
);


```

### Match

Simple match component that allows path and selector based matching.

```js

I will render when at `/foo`

```

You can also pull out params from the path:

```js

{({name}) => (

Hello {name}

)}

```

[react-router]: https://github.com/ReactTraining/react-router
[react-motion]: https://github.com/chenglou/react-motion
[react-hot-loader]: https://github.com/gaearon/react-hot-loader