1234567891011121314151617181920212223242526272829 |
- /**
- * React Static Boilerplate
- * https://github.com/koistya/react-static-boilerplate
- * Copyright (c) Konstantin Tarkus (@koistya) | MIT license
- */
- import 'babel/polyfill';
- import React from 'react';
- import ReactDOM from 'react-dom';
- import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
- import Location from './lib/Location';
- import Layout from './components/Layout';
- const routes = {}; // Auto-generated on build. See tools/lib/routes-loader.js
- const route = async (path, callback) => {
- const handler = routes[path] || routes['/404'];
- const component = await handler();
- await callback(<Layout>{React.createElement(component)}</Layout>);
- };
- if (canUseDOM) {
- const container = document.getElementById('app');
- Location.listen(location => {
- route(location.pathname, async (component) => ReactDOM.render(component, container));
- });
- }
- export default { route, routes };
|