Have searched most of the answers in stack but doesn't seem to find any that matches to my scenario. Please help someone.
I have been using react-router-dom v4 and upgraded to v5 but still getting same issue. But It renders once refresh is clicked.
Code is -----
const RedirectToRoute = ({ context, isPreviousLocation }) => {
if (isPreviousLocation) {
return (
<Switch key={shortId.generate()}>
<Redirect to={context.previousLocation} />
</Switch>
);
}
return null;
};
RedirectToRoute.propTypes = {
context: PropTypes.object,
isPreviousLocation: PropTypes.bool,
};
RedirectToRoute.defaultProps = {
context: {},
isPreviousLocation: {},
};
export default RedirectToRoute;
Used this component in main component as ---
<CorrectionForm props={someProps} >
<RedirectToRoute context={context} isPreviousLocation={isPrevLocation} />
<FormUpdateSuccessMessage />
</CorrectionForms >
Tried to change redirect to route like ----
<Switch>
<Route render={() => <Navigate to={context.prevLocation} />} />
<Switch>
or like this when upgraded to v6 ----
<Routes>
<Route render={() => <Navigate to={context.prevLocation} />} />
<Routes />
Nothing seems to work. Please help. Been stuck on this for weeks