Z
Z
zayalexnick2018-05-23 08:00:19
React
zayalexnick, 2018-05-23 08:00:19

How to do react-router-dom routing correctly?

There are 2 containers in App.jsx

<Router>
    <Switch>
        <Route exact path="/" component={Main} />
        <Route path="/auth" component={Auth} />
    </Switch>
</Router>

In Main.jsx
<main>
    <Layout>
        <Sidebar />
        <Switch>
             <Route path="/rigs" render={() => <h1>hello</h1>} />
        </Switch>
    </Layout>
 </main>

That is, I need the Sidebar to be displayed everywhere except /auth/*. When switching to rigs, it is empty. What have I done wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-05-23
@zayalexnick

Your root route has the exact property, which means that the transition to it will be only if the path exactly matches /. The /rigs path will not render the Main component.
You can solve the problem like this:

<Switch>
  <Route path="/auth" component={Auth} />
  <Route path="/" component={Main} />
</Switch>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question