diff --git a/src/components/Authorized/Secured.js b/src/components/Authorized/Secured.js index faf96a00f9ffc9afe1725d056677b570f6c55506..4303883e09780ae07ece9a1c7016f4f4deecb106 100644 --- a/src/components/Authorized/Secured.js +++ b/src/components/Authorized/Secured.js @@ -9,6 +9,17 @@ const Exception403 = () => ( ); +// Determine whether the incoming component has been instantiated +// AuthorizedRoute is already instantiated +// Authorized render is already instantiated, children is no instantiated +// Secured is not instantiated +const checkIsInstantiation = (target) => { + if (!React.isValidElement(target)) { + return target; + } + return () => target; +}; + /** * 用于判断是否拥有权限访问此view权限 * authority 支持传入 string ,funtion:()=>boolean|Promise @@ -38,7 +49,8 @@ const authorize = (authority, error) => { throw new Error('authority is required'); } return function decideAuthority(targer) { - return () => CheckPermissions(authority, targer, classError || Exception403); + const component = CheckPermissions(authority, targer, classError || Exception403); + return checkIsInstantiation(component); }; };