Created
October 4, 2015 12:18
-
-
Save gnz00/7ad5b353827b5cbafb4e to your computer and use it in GitHub Desktop.
React-Nprogress
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
/*! React Starter Kit | MIT License | http://www.reactstarterkit.com/ */ | |
import React from 'react'; | |
import Router from 'react-routing/src/Router'; | |
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment'; | |
import http from './core/HttpClient'; | |
import App from './components/App'; | |
import IndexPage from './components/IndexPage'; | |
import NotFoundPage from './components/NotFoundPage'; | |
import ErrorPage from './components/ErrorPage'; | |
import NProgress from 'react-nprogress'; | |
const router = new Router(on => { | |
on('*', async (state, next) => { | |
if (canUseDOM) | |
NProgress.start(); | |
const component = await next(); | |
if (canUseDOM) | |
NProgress.done(); | |
return component && <App context={state.context}>{component}</App>; | |
}); | |
on('/', async () => { | |
let data = await getDataMock("/api/people"); | |
return <IndexPage name={data}/> | |
}); | |
on('error', (state, error) => { | |
console.log(error); | |
console.log(state); | |
return state.statusCode === 404 ? | |
<App context={state.context} error={error}><NotFoundPage /></App> : | |
<App context={state.context} error={error}><ErrorPage /></App> | |
} | |
); | |
}); | |
export default router; | |
var getDataMock = function(url) { | |
return new Promise(function(resolve, reject) { | |
setTimeout(function() { | |
resolve([{ name: "Jake" }]); | |
}, 10000); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment