app.js 894 B

1234567891011121314151617181920212223242526272829
  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 ReactDOM from 'react-dom';
  9. import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
  10. import Location from './lib/Location';
  11. import Layout from './components/Layout';
  12. const routes = {}; // Auto-generated on build. See tools/lib/routes-loader.js
  13. const route = async (path, callback) => {
  14. const handler = routes[path] || routes['/404'];
  15. const component = await handler();
  16. await callback(<Layout>{React.createElement(component)}</Layout>);
  17. };
  18. if (canUseDOM) {
  19. const container = document.getElementById('app');
  20. Location.listen(location => {
  21. route(location.pathname, async (component) => ReactDOM.render(component, container));
  22. });
  23. }
  24. export default { route, routes };