0

How can I redirect to 'Notfound' page when wrong url is entered.

I have following Routes:

<Switch>
    <Route path="/about" component={About} />
    <Route path="/contact" component={Contact} />
    <Route path="/dashboard" component={Dashboard} />
    <Route path="/" component={Home} />
    <Route path="**" component={Notfound} />
</Switch>

I have tried "**" as path but this did not worked.

Can anybody please help me?

nas
  • 2,289
  • 5
  • 32
  • 67
  • i think this is a duplicate question https://stackoverflow.com/questions/49181678/404-page-in-react – James Li Aug 28 '19 at 04:01

1 Answers1

2

A <Route> with no path always matches. So you can try something like this:

<Switch>
  <Route path="/about" component={About} />
  <Route path="/contact" component={Contact} />
  <Route path="/dashboard" component={Dashboard} />
  <Route path="/" component={Home} />

  <Route component={Notfound}/>
</Switch>
user9408899
  • 4,202
  • 3
  • 19
  • 32