app.js 857 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * React Static Boilerplate
  3. * https://github.com/koistya/react-static-boilerplate
  4. * Copyright (c) Konstantin Tarkus (@koistya) | MIT license
  5. */
  6. import 'babel/polyfill';
  7. import React from 'react';
  8. import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
  9. import Location from './lib/Location';
  10. import Layout from './components/Layout';
  11. const routes = {}; // Auto-generated on build. See tools/lib/routes-loader.js
  12. const route = async (path, callback) => {
  13. const handler = routes[path] || routes['/404'];
  14. const component = await handler();
  15. await callback(<Layout>{React.createElement(component)}</Layout>);
  16. };
  17. if (canUseDOM) {
  18. const container = document.getElementById('app');
  19. Location.listen(location => {
  20. route(location.pathname, async (component) => React.render(component, container));
  21. });
  22. }
  23. export default { route, routes };