mirror of
https://github.com/ansible/awx.git
synced 2026-02-02 10:08:10 -03:30
refactor auth redirect and add ConditionalRedirect unit tests and App unit and functional tests
This commit is contained in:
22
src/components/ConditionalRedirect.jsx
Normal file
22
src/components/ConditionalRedirect.jsx
Normal 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;
|
||||
Reference in New Issue
Block a user