Skip to content

Instantly share code, notes, and snippets.

@colingourlay

colingourlay/app.jsx

Created Feb 26, 2014
Embed
What would you like to do?
Using react-router-component to drive the routing of a Cordova app (while still working as a web app).
function init() {
var HomePage = React.createClass({
render: function() {
return <div>Home</div>;
}
});
var NotFoundPage = React.createClass({
render: function() {
return <div>404</div>;
}
});
var App = React.createClass({
componentDidMount: function () {
if ('Cordova' in window) {
this.refs.router.navigate('/');
}
},
render: function() {
return (
<Locations ref="router">
<Location path="/" handler={HomePage} />
<NotFound handler={NotFoundPage} />
</Locations>
);
}
});
React.renderComponent(<App />, document.body);
};
if (window.location.protocol === 'file:') {
document.addEventListener('deviceready', init, false);
} else {
init();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment