Last active
February 1, 2017 23:59
-
-
Save DreySkee/8fde41bb3adaedf0ecb5fb63e55ad0db to your computer and use it in GitHub Desktop.
12 - Wordpress API + ReactJS
This file contains hidden or 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 from 'react'; | |
import {render} from 'react-dom'; | |
import App from './components/App.js'; | |
import Home from './components/Home.js'; | |
import { | |
browserHistory, | |
IndexRoute, | |
Redirect, | |
Route, | |
Router | |
} from 'react-router'; | |
import DataActions from './actions/DataActions.js'; | |
class AppInitializer { | |
buildRoutes(data) { | |
return data.pages.map((page, i) => { | |
return ( | |
<Route | |
component={ Home } | |
key={ page.id } | |
path={`/${page.slug}`} | |
/> | |
); | |
}); | |
} | |
run() { | |
DataActions.getPages((response)=>{ | |
render( | |
<Router history={browserHistory}> | |
<Route path="/" component={ App } > | |
<IndexRoute component={ Home } /> | |
{this.buildRoutes(response)} | |
</Route> | |
<Redirect from="*" to="/" /> | |
</Router> | |
, document.getElementById('app') | |
); | |
}); | |
} | |
} | |
new AppInitializer().run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment