Authorized.js 631 Bytes
Newer Older
afc163's avatar
afc163 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import React from 'react';
import RenderAuthorized from '@/components/Authorized';
import Exception from '@/components/Exception';
import { matchRoutes } from 'react-router-config';

const Authorized = RenderAuthorized('user');
const noMatch = <Exception type="403" style={{ minHeight: 500, height: '80%' }} />;

export default ({ children, route, location }) => {
  const branch =
    matchRoutes(route.routes, location.pathname).filter(item => item.match.isExact)[0] || {};
  const { authority } = branch.route || {};
  return (
    <Authorized authority={authority} noMatch={noMatch}>
      {children}
    </Authorized>
  );
};