6

I want to redirect from any * route to my home page, because I want to change url to '/'.

I followed this link:

React-Router: No Not Found Route?

But when I want to change any route path It moves me independently to the url '/'

<Route exact path="/" component={MMPStudio} />
<Route exact path="/galeria" component={Gallery} />
<Route exact path="/kontakt" component={Contact} />
<Route exact path="/fotobudka" component={Fotobudka} />
<Route exact path="/jubiler" component={Jubiler} />{" "}
<Route exact path="/fotobudka/kontakt" component={FotobudkaContact} />
<Route exact path="/jubiler/galeria" component={JubilerGallery} />

<Switch>
    <Route exact path="/" component={MMPStudio} />
    <Redirect from="*" to='/' />
</Switch>
Freestyle09
  • 4,894
  • 8
  • 52
  • 83

1 Answers1

10

I think your switch should wrap the whole thing:

   <Switch>
      <Route exact path="/" component={MMPStudio} />
      <Route exact path="/galeria" component={Gallery} />
      <Route exact path="/kontakt" component={Contact} />
      <Route exact path="/fotobudka" component={Fotobudka} />
      <Route exact path="/jubiler" component={Jubiler} />
      <Route exact path="/fotobudka/kontakt" component={FotobudkaContact} />
      <Route exact path="/jubiler/galeria" component={JubilerGallery} />
      <Redirect from="*" to='/' />
    </Switch>
Bashar Ali Labadi
  • 1,014
  • 1
  • 11
  • 19
  • Yeah it works, but when I redirect with this my logo image is not loading properly, when I change to other url and back to '/' image is loaded properly. I'm getting this error: 'GET http://localhost:3000/fotobudka/logo_studio.png 404 (Not Found)' – Freestyle09 Oct 24 '18 at 18:13