Rewrite old URL to new URL react router v6

I am redesigning a website that was written in html before. old website had a html page for every route. for SEO purposes I needed old urls to work. basically the requirement is rewite/ redirect old url to matching route in react application.

Below is the code snippet I came up with.

const { pathname } = useLocation();
const navigate = useNavigate();

  useEffect(() => {
    if (pathname.includes(".html")) {
      switch (pathname) {
        case "/index.html":
          navigate("/");
        default:
          const path = pathname.split(".html")[0];
          navigate(path);
      }
    }
  }, [pathname]);

This check the pathname includes ‘.html’ and navigate to correct route. You can update the code as your requirement.