Authorized.js 519 Bytes
Newer Older
1 2 3
import React from 'react';
import { Result } from 'antd';
import check from './CheckPermissions';
dengxiaofeng's avatar
dengxiaofeng committed
4

5 6
const Authorized = ({
  children,
张烨's avatar
张烨 committed
7
  authority, // 当前组件渲染需要的权限
8 9 10 11 12 13 14 15 16 17 18 19 20 21
  noMatch = (
    <Result
      status="403"
      title="403"
      subTitle="Sorry, you are not authorized to access this page."
    />
  ),
}) => {
  const childrenRender = typeof children === 'undefined' ? null : children;
  const dom = check(authority, childrenRender, noMatch);
  return <>{dom}</>;
};

export default Authorized;