如何从通配符路由重定向到主页?

时间:2018-10-24 17:57:45

标签: html reactjs react-router

我想从任何*路由重定向到我的主页,因为我想将url更改为“ /”。

我点击了此链接:

React-Router: No Not Found Route?

但是当我想更改任何路径路径时,它会将我独立移动到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>

1 个答案:

答案 0 :(得分:2)

我认为您的开关应该包装整个东西:

   <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>