A
A
Artur Kudashev2019-10-03 18:52:12
React
Artur Kudashev, 2019-10-03 18:52:12

How to make route for 404 page?

Hello, I made a Route for 404 page, but it doesn't work as it should.
This is what the switch looks like:

<Switch>
    <Route path = '/'>
       <BigComponent>
           <Switch
               <Route path = '/contacts' component = { ContactsPage } />
               <Route path = '/payment' component = { PaymentPage } />
           </Switch>
       </BigComponent>
    </Route>
    <Route component = { NotFoundPage } />
</Switch>

The problem is that if I pass /asd for example, the BigComponent will appear. If I add exact to the first Route, contacts and payment won't work. I need all paths except /, /contacts, /payment to load NotFoundPage.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2019-10-03
@archi_kud

you can put a third route in the switch, something like

<Switch>
  <Route path = '/contacts' component = { ContactsPage } />
  <Route path = '/payment' component = { PaymentPage } />
  <Route render={() => { return <Redirect to="/" />; }} />
</Switch>

should work, but somehow so-so that the child component will do redirects
or such
https://stackoverflow.com/a/43877138

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question