Not able to go back to original page from where React Router - Redirect was called

Viewed 38

Problem: Currently app is redirecting user from PageA to ErrorPage if some data is not found on PageA using react-router redirect. Now when the user is on ErrorPage and clicks on the browser back button. IT DOES NOT take back to PageA Here is a code example ` //PageA - this component is inside BrowserRouter

import React from 'react'

const PageA = () = {
    const data = null
    return (
        data ? (<PageAComponent />) : (
        <Redirect
                to={{
                        pathname: "/errorPage",
                        state: { referrer: 'PageA' }
                }}
        />
        )
    )
}

//ErrorPage

import React from 'react'

const ErrorPage = () = {
    return (
        <>.....something is displayed.....</>)
    )
}
1 Answers

According to the documentation, you need to set the push prop on Redirect to true to prevent it from replacing the current entry on the history stack when redirecting.

Related