# hapi-redux-router

> hapi plugin to enable server-side react-router with redux.

Latest version **1.2.1** (published 2016-06-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install hapi-redux-router
pnpm add hapi-redux-router
yarn add hapi-redux-router
bun add hapi-redux-router
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2016-06-16 |
| First published | 2016-01-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 8 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Prashant Tiwari |
| Maintainers | prashaantt |

## Links

- npm: https://www.npmjs.com/package/hapi-redux-router
- Repository: https://github.com/prashaantt/hapi-redux-router
- Issues: https://github.com/prashaantt/hapi-redux-router/issues
- npm.io page: https://npm.io/package/hapi-redux-router

## Dependencies (8)

- [joi](https://npm.io/package/joi.md) 8.1.0
- [boom](https://npm.io/package/boom.md) 3.1.3
- [react](https://npm.io/package/react.md) 15.0.2
- [redux](https://npm.io/package/redux.md) 3.5.2
- [vision](https://npm.io/package/vision.md) 4.1.0
- [react-dom](https://npm.io/package/react-dom.md) 15.0.2
- [react-redux](https://npm.io/package/react-redux.md) 4.4.5
- [react-router](https://npm.io/package/react-router.md) 2.4.0

## Recent versions

- 1.2.1 (latest) — 2016-06-16
- 1.2.0 — 2016-01-21
- 1.1.0 — 2016-01-21
- 0.0.2 — 2016-01-18
- 0.0.1 — 2016-01-18
- 1.0.0 — 2016-01-18

## README

> ## Update

> Deprecated in favour of https://github.com/prashaantt/hapi-react-ssr.

# hapi-redux-router

Currently only supports manifest-style route declarations.

[![Dependency Status](https://david-dm.org/prashaantt/hapi-redux-router.svg)](https://david-dm.org/prashaantt/hapi-redux-router)
[![devDependency Status](https://david-dm.org/prashaantt/hapi-redux-router/dev-status.svg?theme=shields.io)](https://david-dm.org/prashaantt/hapi-redux-router#info=devDependencies)

## Installation

```bash
$ npm install hapi-redux-router --save
```


## Usage

Define your routes as a manifest:

```js
const App = require('./App');
const Homepage = require('./Homepage');


const routes = [
    {
        path: '/',
        component: App,
        indexRoute: { component: Homepage },
        childRoutes: [...]
    }
];


module.exports = routes;
```

Require and register normally as a hapi plugin ([vision](https://github.com/hapijs/vision) is a dependency for rendering the template):

```js
const HapiReduxRouter = require('hapi-redux-router');
const Vision = require('vision');


server.register([
    {
        register: Vision
    },
    {
        register: HapiReduxRouter,
        options: {...}
    }
]); 
```


## Options

The plugin accepts the following ```options```:

- ```store``` (Object - optional): The redux store, generally created using ```Redux.createStore()```, but stores created with redux middleware work just fine too.
- ```routes``` (Array - required): The routes to React components declared as a manifest.
- ```bootstrapAction``` (Function - optional): The redux action to dispatch to load the initial data.
- ```template``` (String - required): The template file ```/path/name``` to use for rendering the view. Internally uses ```reply.view``` provided by ```vision```. The templating engine to use is up to you. See [vision](https://github.com/hapijs/vision) docs.
- ```params``` (Object - optional): Additional params to pass to the template context object. ```componentRenderedToString``` and ```initialState``` are reserved for internal use (see below).


## Notes


- This plugin uses ```componentRenderedToString``` prop to store the server-side rendered root React component, and ```initialState``` to store the computed initial state from the Redux store. Include them appropriately in your template.

```hbs
{{! handlebars example }}

<html>
<body>
    <div id="react-root">{{{ componentRenderedToString }}}</div>
    <script type="application/javascript">
        {{#if initialState}}
        window.__INITIAL_STATE__ = {{{ initialState }}};
        {{/if}}
    </script>
</body>
</html>
```


- If you're using ES6-style module exports for routes and action files, ensure to pass their appropriate exports to this plugin.

```js
const reducer = require('./my-reducer').default;
const bootstrapAction = require('../my-actions').defaultAction;
```


- This plugin uses a catch-all hapi route to pass all incoming requests to the react-router. You will generally need to override this behaviour with other more specific routes in your app — to serve static files, for example.  


## Example

Look at [hapi-react-transform-boilerplate](https://github.com/prashaantt/hapi-react-transform-boilerplate) to see this plugin in action. 


## License

MIT

---
_Source: https://npm.io/package/hapi-redux-router · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
