Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I redirect from wildcard routes to the home page?

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>
like image 282
Freestyle09 Avatar asked Mar 06 '23 05:03

Freestyle09


1 Answers

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>
like image 198
Bashar Ali Labadi Avatar answered Mar 27 '23 05:03

Bashar Ali Labadi