Skip to content

nirmaoz/react-router6-redirect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;
}