【问题标题】:how to render separated routes in different components如何在不同的组件中渲染分离的路线
【发布时间】:2021-08-11 00:56:25
【问题描述】:

您好,我如何渲染实际上在不同组件上分离的路由,例如我的仪表板有 2 条路由,里面有 2 个组件,而我的 App.js 拥有所有其余的。 而且我无法从仪表板内部重定向到 /login,它不会从仪表板内部重定向(我使用 history.push("/login"))

更新:

我的代码是这样的 dashboard.js 组件

<Router>
....mycomponent
<switch>
<Route path="/cutomers"><CutomersComponent><Route>
<Route path="/sales"><SalesComponent><Route>
</switch>
</Router>

app.js 组件

<Router>
....mycomponent
<switch>
<Route path="/login"><Login><Route>
<Route path="/dashbord"><Dashbord><Route>
</switch>
</Router>

【问题讨论】:

标签: reactjs react-router


【解决方案1】:

解决方案是简单地从反应路由器 v5 迁移到反应路由器 v6 这是一个 github repo,我做了解释

https://github.com/w4t3r-45/react-router-v6

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-15
    • 2018-12-16
    • 2022-01-18
    • 2012-01-21
    • 2018-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多