UNPKG

@antdp/authorized

Version:

通过判断是否进入主界面还是登录界面。

34 lines 1.12 kB
import _extends from "@babel/runtime/helpers/extends"; import React, { useMemo } from 'react'; import { Navigate } from "react-router-dom"; import { // FormatBtn as AuthorizedBtn, getFormatPage as getAuthorizedPage } from './format'; import { AuthButton as AuthorizedBtn } from "./AuthButton"; import { jsx as _jsx } from "react/jsx-runtime"; export * from "./hooks"; export * from "./AuthButton"; export * from "./interface"; export { AuthorizedBtn, getAuthorizedPage }; var Authorized = props => { if (props.authority) { return /*#__PURE__*/_jsx(React.Fragment, { children: React.Children.map(props.children, child => { if (! /*#__PURE__*/React.isValidElement(child)) return child; return /*#__PURE__*/React.cloneElement(child, _extends({}, child.props)); }) }); } return useMemo(() => { if (props.redirectPath) { return /*#__PURE__*/_jsx(Navigate, { to: props.redirectPath, replace: true }); } return /*#__PURE__*/_jsx(React.Fragment, { children: props.children }); }, [props.redirectPath]); }; export default Authorized;