1.0.1 • Published 2 years ago

react-router6-redirect v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-router6-redirect

Redirect component for react-router v6. Renders a <Navigate replace/> component and handles any dynamic parts.

Why is this needed?

react-router v6 <Navigate> component does not handle dynamic parts of the to prop.

Install

npm i react-router6-redirect

Setup

import {Route} from 'react-router-dom'
import {Redirect} from 'react-router6-redirect'; 

Usage

Important: each param name present in the Redirect's to prop must exist in the Route's path prop.

<Route path="original/path/:id" element={<Redirect to="different/:id"/>}/>

Supported props

export interface RedirectProps {
  to: string;
  state?: any;
  relative?: RelativeRoutingType;
}