refactor auth redirect and add ConditionalRedirect unit tests and App unit and functional tests

This commit is contained in:
John Mitchell
2018-10-24 16:53:16 -04:00
parent 0373058540
commit 3938d49a1f
4 changed files with 131 additions and 52 deletions

View File

@@ -0,0 +1,22 @@
import React from 'react';
import {
Route,
Redirect
} from 'react-router-dom';
const ConditionalRedirect = ({ component: Component, shouldRedirect, redirectPath, ...props }) => {
if (shouldRedirect()) {
return (
<Redirect to={{
pathname: redirectPath,
state: { from: props.location }
}}/>
);
} else {
return (
<Route {...props} render={props => (<Component {...props}/>)} />
);
}
};
export default ConditionalRedirect;