Skip to content

Instantly share code, notes, and snippets.

@colingourlay
Created February 26, 2014 23:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colingourlay/9241439 to your computer and use it in GitHub Desktop.
Save colingourlay/9241439 to your computer and use it in GitHub Desktop.
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