React home and share pages working isomorphically
This commit is contained in:
parent
0b00b190fc
commit
a2148dc00a
21 changed files with 482 additions and 658 deletions
62
views/app.jsx
Normal file
62
views/app.jsx
Normal file
|
@ -0,0 +1,62 @@
|
|||
'use strict';
|
||||
|
||||
var request = require('superagent');
|
||||
var React = require('react');
|
||||
var Router = require('react-router');
|
||||
var Route = require('react-router').Route;
|
||||
var DefaultRoute = require('react-router').DefaultRoute;
|
||||
var NotFoundRoute = require('react-router').NotFoundRoute;
|
||||
var RouteHandler = require('react-router').RouteHandler;
|
||||
var Home = require('./home.jsx');
|
||||
var Share = require('./share.jsx');
|
||||
var Error = require('./error.jsx');
|
||||
var Head = require('./head.jsx');
|
||||
var ga = require('react-google-analytics');
|
||||
var GAInitiailizer = ga.Initializer;
|
||||
|
||||
var App = React.createClass({
|
||||
|
||||
render: function () {
|
||||
|
||||
return (
|
||||
<html>
|
||||
<Head />
|
||||
<body className="home">
|
||||
<RouteHandler {...this.props} />
|
||||
<GAInitiailizer />
|
||||
<script src="/javascript/bundle.js" />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
var NotFound = React.createClass({
|
||||
render: function () {
|
||||
return <h2>Not found</h2>;
|
||||
}
|
||||
});
|
||||
|
||||
var routes = (
|
||||
<Route name="home" handler={App} path="/">
|
||||
<DefaultRoute handler={Home} />
|
||||
<Route name="share" path=":service/:type/:id" handler={Share}/>
|
||||
<NotFoundRoute handler={NotFound}/>
|
||||
</Route>
|
||||
);
|
||||
|
||||
module.exports.routes = routes;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.onload = function() {
|
||||
Router.run(routes, Router.HistoryLocation, function (Handler) {
|
||||
if (typeof recents !== "undefined") {
|
||||
React.render(<Handler recents={recents} />, document);
|
||||
} else if (typeof shares !== "undefined") {
|
||||
React.render(<Handler shares={shares} />, document);
|
||||
}
|
||||
});
|
||||
ga('create', 'UA-66209-8', 'auto');
|
||||
ga('send', 'pageview');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue