Created
September 13, 2016 19:43
-
-
Save morgondag/348d1905f7fb6f05a896ce829cef8ee6 to your computer and use it in GitHub Desktop.
basic auth example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { render } from 'react-dom' | |
import { browserHistory, Router, Route, Link, withRouter } from 'react-router' | |
import { checkAuth } from './utils/auth.jsx' | |
import App from './components/app.jsx' | |
import Dashboard from './components/dashboard.jsx' | |
import Register from './components/register.jsx' | |
import Forgot from './components/forgot.jsx' | |
import Pwd from './components/pwd.jsx' | |
import NoMatch from './components/nomatch.jsx' | |
const Auth = (nextState, replace) => { | |
return checkAuth().catch(()=>{ | |
browserHistory.push('/'); | |
}) | |
} | |
window.addEventListener('DOMContentLoaded', ()=> { | |
render(( | |
<Router history={browserHistory}> | |
<Route path="/" component={App}> | |
<Route path="dashboard" component={Dashboard} onEnter={Auth} /> | |
</Route> | |
<Route path="register" component={Register} /> | |
<Route path="forgot" component={Forgot} /> | |
<Route path="pwd" component={Pwd} /> | |
<Route path="*" component={NoMatch}/> | |
</Router> | |
), document.querySelector('section')) | |
}, false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment