Skip to content

Instantly share code, notes, and snippets.

@bnhansn
Last active October 21, 2016 15:20
Show Gist options
  • Save bnhansn/e5766bb2f7c2119216495886aefaed67 to your computer and use it in GitHub Desktop.
Save bnhansn/e5766bb2f7c2119216495886aefaed67 to your computer and use it in GitHub Desktop.
// @flow
import React, { Component } from 'react';
import { BrowserRouter, Match, Miss } from 'react-router';
import { connect } from 'react-redux';
import { authenticate } from '../../actions/session';
import Home from '../Home';
import NotFound from '../../components/NotFound';
import Login from '../Login';
import Signup from '../Signup';
type Props = {
authenticate: () => void,
}
class App extends Component {
componentDidMount() {
const token = localStorage.getItem('token');
if (token) {
this.props.authenticate();
}
}
props: Props
render() {
return (
<BrowserRouter>
<div style={{ display: 'flex', flex: '1' }}>
<Match exactly pattern="/" component={Home} />
<Match pattern="/login" component={Login} />
<Match pattern="/signup" component={Signup} />
<Miss component={NotFound} />
</div>
</BrowserRouter>
);
}
}
export default connect(
null,
{ authenticate }
)(App);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment