import React from 'react' ; import { Location } from 'history' ; import { Redirect , useLocation , RouteComponentProps } from 'react-router-dom' ; param pathname export function redirectTo ( pathname ) { return ( { location } ) => { return < RenderRedirectTo location = { location } pathname = { pathname } / > ; } ; } param param0 export function RedirectTo ( { pathname } ) { const location = useLocation ( ) ; return < RenderRedirectTo location = { location } pathname = { pathname } / > ; } interface Props { location : Location ; pathname : string ; } /**
 * Given a pathname, redirect to that location, preserving the search and maintaining
 * backward-compatibilty with legacy (pre-7.9) hash-based URLs.
 */ function RenderRedirectTo ( props ) { const { location } = props ; let search = location . search ; let pathname = props . pathname ; if ( location . pathname === '' && location . hash . length > 0 ) { const resolvedUrl = new URL ( location . hash . slice ( 1 ) , 'http://localhost' ) ; search = resolvedUrl . search ; pathname = resolvedUrl . pathname ; } return < Redirect to = { { ... location , hash : '' , pathname , search } } />; }