import React from 'react';
import {IndexRoute, Route} from 'react-router';
import { isLoaded as isAuthLoaded, load as loadAuth } from 'redux/modules/auth';
import {
    App,
    Chat,
    Home,
    Widgets,
    About,
    Login,
    LoginSuccess,
    Survey,
    NotFound,
    Pagination,
    Hello,
    Product,
    CustomerOrder,
    AddNewCustomAttribute,
    AddGwpByExcel,
    OrderDetailCancelDetail,
    AccountEdit,
    AccountSetting,
    ProductBestSeller,
    ProductExclusive,
    ProductManageCustomAttribute,
    ProductHotItem,
  } from 'containers';

export default (store) => {
  const requireLogin = (nextState, replace, cb) => {
    function checkAuth() {
      const { auth: { user }} = store.getState();
      if (!user) {
        // oops, not logged in, so can't be here!
        replace('/');
      }
      cb();
    }

    if (!isAuthLoaded(store.getState())) {
      store.dispatch(loadAuth()).then(checkAuth);
    } else {
      checkAuth();
    }
  };

  /**
   * Please keep routes in alphabetical order
   */
  return (
    <Route path="/" component={App}>
      { /* Home (main) route */ }
      <IndexRoute component={Home}/>

      { /* Routes requiring login */ }
      <Route onEnter={requireLogin}>
        <Route path="chat" component={Chat}/>
        <Route path="loginSuccess" component={LoginSuccess}/>
      </Route>

      { /* Routes */ }
      <Route path="about" component={About}/>
      <Route path="login" component={Login}/>
      <Route path="pagination" component={Pagination}/>
      <Route path="survey" component={Survey}/>
      <Route path="widgets" component={Widgets}/>
      <Route path="hello" component={Hello}/>
      <Route path="product" component={Product}/>
      <Route path="product/exclusive" component={ProductExclusive}/>
      <Route path="product/bestseller" component={ProductBestSeller}/>
      <Route path="product/hotitem" component={ProductHotItem}/>
      <Route path="customerorder" component={CustomerOrder}/>
      <Route path="customattribute" component={AddNewCustomAttribute}/>
      <Route path="addgwpbyexcel" component={AddGwpByExcel}/>
      <Route path="orderdetailcanceldetail" component={OrderDetailCancelDetail}/>
      <Route path="accountsetting" component={AccountSetting}/>
      <Route path="accountedit" component={AccountEdit}/>
      <Route path="productmanagecustomattribute" component={ProductManageCustomAttribute}/>
      { /* Catch all route */ }
      <Route path="*" component={NotFound} status={404} />
    </Route>
  );
};

import React from 'react';
import {IndexRoute, Route} from 'react-router';
import { isLoaded as isAuthLoaded, load as loadAuth } from 'redux/modules/auth';
import {
    App,
    Chat,
    Home,
    Widgets,
    About,
    Login,
    LoginSuccess,
    Survey,
    NotFound,
    Pagination,
    Hello,
    Product,
    CustomerOrder,
    AddNewCustomAttribute,
    AddGwpByExcel,
    OrderDetailCancelDetail,
    AccountEdit,
    AccountSetting,
    ProductBestSeller,
    ProductExclusive,
    ProductManageCustomAttribute,
    ProductHotItem,


  } from 'containers';

export default (store) => {
  const requireLogin = (nextState, replace, cb) => {
    function checkAuth() {
      const { auth: { user }} = store.getState();
      if (!user) {
        // oops, not logged in, so can't be here!
        replace('/');
      }
      cb();
    }

    if (!isAuthLoaded(store.getState())) {
      store.dispatch(loadAuth()).then(checkAuth);
    } else {
      checkAuth();
    }
  };

  /**
   * Please keep routes in alphabetical order
   */
  return (
    <Route path="/" component={App}>
      { /* Home (main) route */ }
      <IndexRoute component={Home}/>

      { /* Routes requiring login */ }
      <Route onEnter={requireLogin}>
        <Route path="chat" component={Chat}/>
        <Route path="loginSuccess" component={LoginSuccess}/>
      </Route>

      { /* Routes */ }
      <Route path="about" component={About}/>
      <Route path="login" component={Login}/>
      <Route path="pagination" component={Pagination}/>
      <Route path="survey" component={Survey}/>
      <Route path="widgets" component={Widgets}/>
      <Route path="hello" component={Hello}/>
      <Route path="product" component={Product}/>
      <Route path="product/exclusive" component={ProductExclusive}/>
      <Route path="product/bestseller" component={ProductBestSeller}/>
      <Route path="product/hotitem" component={ProductHotItem}/>
      <Route path="customerorder" component={CustomerOrder}/>
      <Route path="customattribute" component={AddNewCustomAttribute}/>
      <Route path="addgwpbyexcel" component={AddGwpByExcel}/>
      <Route path="orderdetailcanceldetail" component={OrderDetailCancelDetail}/>
      <Route path="accountsetting" component={AccountSetting}/>
      <Route path="accountedit" component={AccountEdit}/>
      <Route path="productmanagecustomattribute" component={ProductManageCustomAttribute}/>
      { /* Catch all route */ }
      <Route path="*" component={NotFound} status={404} />
    </Route>
  );
};

delete wrong path