diff --git a/src/components/Authorized/Authorized.js b/src/components/Authorized/Authorized.js
index d9a2a781d4a34b3b6c49f7c0a9571ce98102a9ba..8e7aacb21f921ccc31cf22c1d0d9af6a8459aa8d 100644
--- a/src/components/Authorized/Authorized.js
+++ b/src/components/Authorized/Authorized.js
@@ -5,11 +5,7 @@ class Authorized extends React.Component {
render() {
const { children, authority, noMatch = null } = this.props;
const childrenRender = typeof children === 'undefined' ? null : children;
- return CheckPermissions(
- authority,
- childrenRender,
- noMatch
- );
+ return CheckPermissions(authority, childrenRender, noMatch);
}
}
diff --git a/src/components/Authorized/AuthorizedRoute.js b/src/components/Authorized/AuthorizedRoute.js
index 3d03226abee91d973468871a092ead775e039b1f..f7cd679d955e8ca532e680e001b01aa716bec775 100644
--- a/src/components/Authorized/AuthorizedRoute.js
+++ b/src/components/Authorized/AuthorizedRoute.js
@@ -4,16 +4,28 @@ import Authorized from './Authorized';
class AuthorizedRoute extends React.Component {
render() {
- const { component: Component, render, authority,
- redirectPath, ...rest } = this.props;
+ const {
+ component: Component,
+ render,
+ authority,
+ redirectPath,
+ ...rest
+ } = this.props;
return (
} />}
+ noMatch={
+ }
+ />
+ }
>
(Component ? : render(props))}
+ render={props =>
+ (Component ? : render(props))
+ }
/>
);
diff --git a/src/components/Authorized/CheckPermissions.js b/src/components/Authorized/CheckPermissions.js
index 7a8239c26c12066628aca000f211e16352030ddb..d51e98333014d1705fab88d2ee13ae0c1d1948dc 100644
--- a/src/components/Authorized/CheckPermissions.js
+++ b/src/components/Authorized/CheckPermissions.js
@@ -3,7 +3,11 @@ import PromiseRender from './PromiseRender';
import { CURRENT } from './index';
function isPromise(obj) {
- return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
+ return (
+ !!obj &&
+ (typeof obj === 'object' || typeof obj === 'function') &&
+ typeof obj.then === 'function'
+ );
}
/**
diff --git a/src/components/Authorized/PromiseRender.js b/src/components/Authorized/PromiseRender.js
index 06975f8ae7aa569bb4abcd287235e16ab32c8327..22f1fcb720af8bf4e3f3c769b9c9bf5a46945958 100644
--- a/src/components/Authorized/PromiseRender.js
+++ b/src/components/Authorized/PromiseRender.js
@@ -6,22 +6,34 @@ export default class PromiseRender extends React.PureComponent {
component: null,
};
componentDidMount() {
+ const ok = this.checkIsInstantiation(this.props.ok);
+ const error = this.checkIsInstantiation(this.props.error);
this.props.promise
.then(() => {
this.setState({
- component: this.props.ok,
+ component: ok,
});
})
.catch(() => {
this.setState({
- component: () => this.props.error,
+ component: error,
});
});
}
+ // 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
+ checkIsInstantiation = (target) => {
+ if (!React.isValidElement(target)) {
+ return target;
+ }
+ return () => target;
+ };
render() {
- const C = this.state.component;
- return C ? (
-
+ const Component = this.state.component;
+ return Component ? (
+
) : (
{
throw new Error('authority is required');
}
return function decideAuthority(targer) {
- return () => CheckPermissions(
- authority,
- targer,
- classError || Exception403
- );
+ return () => CheckPermissions(authority, targer, classError || Exception403);
};
};