我如何将我的应用程序与 react-router-dom 的路由捆绑在一起?
how can i bundle my app with Route of react-router-dom?
与第一个图像一样,页面将为名为内容的组件呈现路由。第二个不会正确地使用重定向呈现,我该如何解决这个问题?先谢谢了
尝试使用Switch
:
import { Route, Switch } from 'react-router-dom'
...
return (
<div>
<Header />
<Switch>
<Route path="/content" component={Content} />
<Redirect from="/" to="/content" push />
</Switch>
<Footer />
</div>
);
它最终会做你想做的事。
与第一个图像一样,页面将为名为内容的组件呈现路由。第二个不会正确地使用重定向呈现,我该如何解决这个问题?先谢谢了
尝试使用Switch
:
import { Route, Switch } from 'react-router-dom'
...
return (
<div>
<Header />
<Switch>
<Route path="/content" component={Content} />
<Redirect from="/" to="/content" push />
</Switch>
<Footer />
</div>
);
它最终会做你想做的事。