Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* main application
*/
import React from 'react'
import ReactDOM from 'react-dom'
import page from 'page'
/* Component */
let Page1 = React.createClass({
render(){
return (<div><a href="/home/user">index!</a></div>)
}
});
let Page2 = React.createClass({
render(){
return (<div><a href="/home/">user!</a></div>)
}
});
let Router = React.createClass({
componentDidMount() {
let self = this;
this.props.routes.forEach(function (route) {
let url = route[0];
let Component = route[1];
page(url, function (ctx) {
self.setState({
component: <Component params={ctx.params} querystring={ctx.querystring} />
});
});
});
page.start({hashbang:false});
},
getInitialState() {
return { component: <div>Hola mundo</div>};
},
render() {
return this.state.component;
}
});
/* Routes */
let routes = [
['/home/', Page1],
['/home/user', Page2]
];
/* Render*/
ReactDOM.render(<Router routes={routes} />, document.getElementById('Application'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.