# simple-react-navigation

> Easy to setup stack navigation for react and react-native apps using Redux.

Latest version **1.0.1** (published 2017-04-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install simple-react-navigation
pnpm add simple-react-navigation
yarn add simple-react-navigation
bun add simple-react-navigation
```

## 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.0.1 |
| Published | 2017-04-01 |
| First published | 2017-04-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Joey F. Poon |
| Maintainers | joeypoon |

## Links

- npm: https://www.npmjs.com/package/simple-react-navigation
- Repository: https://github.com/joeypoon/simple-react-navigation
- Homepage: https://github.com/joeypoon/simple-react-navigation#readme
- Issues: https://github.com/joeypoon/simple-react-navigation/issues
- npm.io page: https://npm.io/package/simple-react-navigation

## Dependencies (1)

- [react](https://npm.io/package/react.md) 15.4.2

## Recent versions

- 1.0.1 (latest) — 2017-04-01
- 1.0.0 — 2017-04-01

## README

## simple-react-navigation

Easy to setup stack navigation for react and react-native apps using Redux.

### Installation

npm install simple-react-navigation

### Setup

App.js

		import React from 'react';
		import { Provider } from 'react-redux';

		import store from './store';
		import Main from './components';

		export default function App() {
			return (
				<Provider store={ store }>
					<Main />
				</Provider>
			);
		}


Main.js

		import React from 'react';
		import { connect } from 'react-redux';
		import Navigator from 'simple-react-navigation';

		import { routes } from '../routes';

		function Main(props) {
			return <Navigator routeStack={ props.routeStack } routes={ routes } />
		}

		function mapStateToProps(state) {
			return {
				routeStack: state.routeStack
			};
		}

		export default connect(mapStateToProps)(Main);


routeStack.reducer.js

		import { createReducer } from 'simple-react-navigation';

		const options = {
			defaultRoute: 'Home'
		}
		export default createReducer(options);


routes.js

		import Home from './components/Home';
		import Foo from './components/Foo';

		export const routes = {
			Home: { screen: Home },
			Foo: { screen: Foo }
		};

routeStack.actions.js

		const NAVIGATE = 'NAVIGATE';
		const NAVIGATE_BACK = 'NAVIGATE_BACK';

		export function navigate(route) {
			return {
				type: NAVIGATE,
				route
			};
		}

		export function navigateBack() {
			return {
				type: NAVIGATE_BACK
			}
		}

### Usage

Home.component.js

		import React from 'react';
		import { connect } from 'react-redux';

		import { navigate } from '../../actions/routeStack.actions';

		export function Home(props) {
		  const { navigate } = props;
		  return (
		    <div>
		      <Button onClick={ navigate.bind(this, 'Foo')>
		      	Navigate to 'Foo'
		      </Button>
		    </div>
		  );
		}

		const actions = { navigate };
		export default connect(null, actions)(Home);


Foo.component.js

		import React from 'react';
		import { connect } from 'react-redux';

		import { navigateBack } from '../actions/routeStack.actions';

		function Foo(props) {
			const { navigateBack } = props;
		  return (
		  	<div>
			  	<Button onClick={ navigateBack }>
			  		Navigate back to last active route
			  	</Button>
				</div>
			);
		}

		const actions = { navigateBack };
		export default connect(null, actions)(Foo);

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