From 295580c09bdb717d1766ac04a1a8b7d4cf051902 Mon Sep 17 00:00:00 2001 From: jim Date: Thu, 1 Feb 2018 16:15:37 +0800 Subject: [PATCH] add Secured check instantiation --- src/components/Authorized/Secured.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/Authorized/Secured.js b/src/components/Authorized/Secured.js index faf96a00..4303883e 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); }; }; -- GitLab