Created
February 26, 2014 23:58
-
-
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).
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
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