React Router/5.1/Redirect To Navigate

1.0.1Last update Dec 17, 2024
by@manishjha-04

This codemod updates deprecated Redirect components from react-router-dom to the modern Navigate API. It also updates the imports by replacing Redirect with Navigate.

Before

import { Redirect, Route, Switch } from "react-router-dom";
<Redirect to="/home" />;
<Redirect to="/home" push={true} />;

After

import { Navigate, Route, Switch } from "react-router-dom";
<Navigate to="/home" />;
<Navigate to="/home" replace />;

This change ensures compatibility with newer versions of react-router-dom by using Navigate in place of Redirect.

Build custom codemods

Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community

background illustrationGet Started Now