router.js 1.1 KB
Newer Older
1
import React from 'react';
2
import { routerRedux, Route, Switch } from 'dva/router';
3
import { LocaleProvider } from 'antd';
afc163's avatar
afc163 committed
4
import zhCN from 'antd/lib/locale-provider/zh_CN';
ddcat1115's avatar
ddcat1115 committed
5
import { getRouterData } from './common/router';
ddcat1115's avatar
ddcat1115 committed
6
import Authorized from './utils/Authorized';
7
import { getQueryPath } from './utils/utils';
afc163's avatar
afc163 committed
8

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

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

export default RouterConfig;