content: import React from 'react'
  import ReactDOM from 'react-dom'
  import createBrowserHistory from 'history/lib/createBrowserHistory'
  import { useRouterHistory, match } from 'react-router'
  import { syncHistoryWithStore } from 'react-router-redux'
  import createStore from './store/createStore'
  import AppContainer from './containers/AppContainer'
  import layout from '../config/layout'
  
  // ========================================================
  // Browser History Setup
  // ========================================================
  
  const browserHistory = useRouterHistory(createBrowserHistory)({
    basename: __BASENAME__
  })
  
  // ========================================================
  // Store and History Instantiation
  // ========================================================
  // Create redux store and sync with react-router-redux. We have installed the
  // react-router-redux reducer under the routerKey "router" in src/routes/index.js,
  // so we need to provide a custom `selectLocationState` to inform
  // react-router-redux of its location.
  const initialState = window.___INITIAL_STATE__
  const store = createStore(initialState, browserHistory)
  const history = syncHistoryWithStore(browserHistory, store, {
    selectLocationState: (state) => state.router
  })
  
  // ========================================================
  // Developer Tools Setup
  // ========================================================
  if (0 && __DEBUG__) {
    if (window.devToolsExtension) {
      window.devToolsExtension.open()
    }
  }
  
  // ========================================================
  // Render Setup
  // ========================================================
  const MOUNT_NODE = document.getElementById('root')
  
  let render = (routerKey = null) => {
    const routes = require('./routes/index').default(store)
  
    match({ history, routes }, (error, redirectLocation, renderProps) => {
      // todo: Error handling should be improved
      if (error) {
        console.log(error)
        return
      }
  
      ReactDOM.render(
        <AppContainer
          {...renderProps}
          store={store}
          history={history}
          routes={routes}
          routerKey={routerKey}
          layout={{...layout, ...(window.___LAYOUT__ || {})}}
        />,
        MOUNT_NODE
      )
    })
  }
  
  // Enable HMR and catch runtime errors in RedBox
  // This code is excluded from production bundle
  if (__DEV__ && module.hot) {
    const renderApp = render
    const renderError = (error) => {
      const RedBox = require('redbox-react').default
  
      ReactDOM.render(<RedBox error={error} />, MOUNT_NODE)
    }
    render = () => {
      try {
        renderApp(Math.random())
      } catch (error) {
        renderError(error)
      }
    }
    module.hot.accept(['./routes/index'], () => render())
  }
  
  // ========================================================
  // Go!
  // ========================================================
  render()
  