L
L
LazariusPaskalius2020-05-05 10:31:32
JavaScript
LazariusPaskalius, 2020-05-05 10:31:32

How to cancel redirect when reloading react app?

I am creating a React application that has two pages, after completing the actions on the first, the user gets to the second. It is necessary that when reloading the second page, it does not redirect to the first. I am using react router dom, how can i do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
ssdakj, 2020-05-05
@ssdakj

If I understood everything correctly, then you need to create two routes, and push to the second router after completing the actions, when you reboot, you will remain on the second route

function Page1() {
    const history = useHistory();
    
    const handleClick = () => {
        тут какое-то действие
        history.push('/page2')
    }

    ...
}

...

function App() {
    return (
        <BrowserRouter>
            <Switch>
                <Route path="/page1" component={Page1}/>
                <Route path="/page2" component={Page2}/>
            </Switch>
        </BrowserRouter>
    )
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question