Skip to content

Instantly share code, notes, and snippets.

@gitexec
Last active September 21, 2017 21:51
Show Gist options
  • Save gitexec/cdc5dd363fd8695a0a882e35b801ade3 to your computer and use it in GitHub Desktop.
Save gitexec/cdc5dd363fd8695a0a882e35b801ade3 to your computer and use it in GitHub Desktop.
Simple example of React, Redux, and Router
import {
BrowserRouter as Router,
Link,
Route,
Switch,
} from 'react-router-dom';
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import reducers from './Reducers/ReducersContainer';
const Home = () => <h1>Home</h1>;
const About = () => <h1>About</h1>;
const createStoreWithMiddleware = applyMiddleware()(createStore);
ReactDOM.render(
<Provider store={createStoreWithMiddleware(reducers)}>
<Router>
<div>
<Link to="/">Home</Link>{' '}
<Link to={{ pathname: '/about' }}>About</Link>{' '}
<Link to="/contact">Contact</Link>
<Switch>
<Route path="/" component={Home} />
<Route path="/about" component={About} />
<Route
path="/contact"
render={() => <h1>Contact Us</h1>} />
<Route path="/blog" children={({ match }) => (
<li className={match ? 'active' : ''}>
<Link to="/blog">Blog</Link>
</li>)} />
<Route render={() => <h1>Page not found</h1>} />
</Switch>
</div>
</Router>
</Provider>,
document.getElementById("react-root")
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment