router.js 949 Bytes
Newer Older
1
import React from 'react';
2
import { routerRedux, Route, Switch } from 'dva/router';
ddcat1115's avatar
ddcat1115 committed
3
import { getRouterData } from './common/router';
ddcat1115's avatar
ddcat1115 committed
4
import Authorized from './utils/Authorized';
5
import { getQueryPath } from './utils/utils';
afc163's avatar
afc163 committed
6

7
const { ConnectedRouter } = routerRedux;
ddcat1115's avatar
ddcat1115 committed
8
const { AuthorizedRoute } = Authorized;
WhatAKitty's avatar
WhatAKitty committed
9 10

function RouterConfig({ history, app }) {
ddcat1115's avatar
ddcat1115 committed
11 12 13
  const routerData = getRouterData(app);
  const UserLayout = routerData['/user'].component;
  const BasicLayout = routerData['/'].component;
14
  return (
15 16 17 18 19 20 21 22 23 24 25 26 27
    <ConnectedRouter history={history}>
      <Switch>
        <Route path="/user" component={UserLayout} />
        <AuthorizedRoute
          path="/"
          render={props => <BasicLayout {...props} />}
          authority={['admin', 'user']}
          redirectPath={getQueryPath('/user/login', {
            redirect: window.location.href,
          })}
        />
      </Switch>
    </ConnectedRouter>
28 29 30 31
  );
}

export default RouterConfig;