Skip to content

Instantly share code, notes, and snippets.

@MicheleBertoli
Created November 30, 2015 11:44
Show Gist options
  • Save MicheleBertoli/1425dcca5ced07ab2256 to your computer and use it in GitHub Desktop.
Save MicheleBertoli/1425dcca5ced07ab2256 to your computer and use it in GitHub Desktop.
The simplest SPA ever
<!DOCTYPE html>
<html>
<head>
<title>The simplest SPA ever</title>
<script type="text/javascript">
!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="3.1.0";
analytics.load("YOUR_WRITE_KEY");
}}();
</script>
</head>
<body>
<div id="container"></div>
<script src="https://npmcdn.com/[email protected]/dist/react.min.js"></script>
<script src="https://npmcdn.com/[email protected]/dist/react-dom.min.js"></script>
<script src="https://npmcdn.com/[email protected]/umd/History.min.js"></script>
<script src="https://npmcdn.com/[email protected]/umd/ReactRouter.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.min.js"></script>
<script type="text/babel">
const App = React.createClass({
render() {
return <div>{this.props.children}</div>;
}
});
const One = React.createClass({
render() {
return <ReactRouter.Link to='/two'>Two</ReactRouter.Link>;
}
});
const Two = React.createClass({
render() {
return <ReactRouter.Link to='/three'>Three</ReactRouter.Link>;
}
});
const Three = React.createClass({
render() {
return <div>Bye!</div>;
}
});
const history = History.createHistory();
history.listen(() => analytics.page());
ReactDOM.render((
<ReactRouter.Router history={history}>
<ReactRouter.Route path="/" component={App}>
<ReactRouter.IndexRoute path="one" component={One}/>
<ReactRouter.Route path="two" component={Two}/>
<ReactRouter.Route path="three" component={Three}/>
</ReactRouter.Route>
</ReactRouter.Router>
), document.body)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment