javascriptreactjsreact-router

How to redirect in React Router 7 in Framework mode to another route


I just want to redirect one path to another.

If I have something like this in my routes.ts:

export default [
  index("Home.tsx"),
  route("/about", "About.tsx"),
] satisfies RouteConfig;

How do I say I want to redirect "/info" back to "/about". I was expecting to add a line like:

redirect("/info", "/about"),

But the documentation seems very quiet about such things.

Any ideas?


Solution

  • A redirect is something you would return from a route loader or action, it's a Response object. There is no route config function to call to handle redirecting directly, but you can create a route component that uses a loader to initiate the redirection.

    Example:

    For more complete details see: