index.jsx 1.1 KB
Newer Older
J
Jason Park 已提交
1 2 3
import React from 'react';
import ReactDOM from 'react-dom';
import { combineReducers, createStore } from 'redux';
J
Jason Park 已提交
4
import { BrowserRouter, Route, Switch } from 'react-router-dom';
J
Jason Park 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17
import { Provider } from 'react-redux';
import { routerReducer } from 'react-router-redux';
import App from '/components/App';
import * as reducers from '/reducers';

const MOUNT_NODE = document.getElementById('root');

const store = createStore(combineReducers({ ...reducers, routing: routerReducer }));

const render = (Component) => {
  ReactDOM.render(
    <Provider store={store}>
      <BrowserRouter>
J
Jason Park 已提交
18 19 20 21
        <Switch>
          <Route exact path="/:categoryKey/:algorithmKey/:fileKey" component={Component} />
          <Route path="/" component={Component} />
        </Switch>
J
Jason Park 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
      </BrowserRouter>
    </Provider>,
    MOUNT_NODE
  );
};

render(App);

if (module.hot) {
  module.hot.accept('./components/App/index.jsx', () => {
    const NextApp = require('/components/App').default;
    try {
      render(NextApp);
    } catch (error) {
      const RedBox = require('redbox-react').default;
      ReactDOM.render(<RedBox error={error} />, MOUNT_NODE);
    }
  });
}