UNPKG

@uiw-admin/authorized

Version:
37 lines 959 B
import React from 'react'; import { useNavigate } from 'react-router-dom'; import { jsx as _jsx } from "react/jsx-runtime"; export * from './Auth'; export { default as AuthBtn } from './Auth'; var AuthPage = function AuthPage(props) { if (props === void 0) { props = { children: /*#__PURE__*/_jsx(React.Fragment, {}) }; } var navigate = useNavigate(); /** Navigate 重定向 会报错 */ React.useEffect(() => { if (!props.authority) { if (props.redirectPath) { navigate(props.redirectPath, { replace: true }); } else { navigate('/login', { replace: true }); } } }, [props.redirectPath]); if (props.authority) { return props.children; } return /*#__PURE__*/_jsx(React.Suspense, { fallback: /*#__PURE__*/_jsx("span", { children: "Loading..." }), children: /*#__PURE__*/_jsx(React.Fragment, {}) }); }; export default AuthPage;