A
A
AltaiR2020-06-18 18:58:53
React
AltaiR, 2020-06-18 18:58:53

How to correctly write Redirect in react-router-dom?

Hello. Please see the example code posted on CodeSandbox . When, for example, I go to the "Services" page and refresh the page, it takes me to the "Documents" page. I understand this because of: . He's supposed to redirect to /"documents" only when I go to "/" ? And he always when I update redirects there. <Redirect from="/" to="/documents" exact />

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2020-06-22
@AltaiR-05

Why do you have Suspense inside Switch? It should be higher and then everything will work as it should, i.e. the order is:

<Suspense fallback={<div>loading...</div>}>
  <Switch>
    <Redirect from="/" to="/documents" exact />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question