【发布时间】:2018-08-08 06:33:28
【问题描述】:
我现在正在使用 React 路由器 v4,我想在一个单独的对象中拥有一个路由配置,所以我按照文档进行了类似的操作(参见下面的代码)
我想实现这个流程:当用户移动到客户模块时,例如 "/customer" 应该呈现一个概览组件,然后,我移动到路由 " /customer/cards" 只有卡片组件应该在那里(概览组件应该消失)。但我不知道我该怎么做。
我只找到了一种方法来实现它(只需为 Overview 和 Cards 添加单独的路由。例如 /customer/overview 和 /customer/cards。
但我不想有这个解决方案,因为我想在用户来到“/customer”时准确地呈现概览。
有人可以帮我提些建议吗?我会很合适的。
这是最小工作方案的演示:Minimal working demo of the issue
const routes: any = [
{
path : "/",
component : AsHm,
exact : true
},
{
path : "/about",
component : AsAb,
exact : true
},
{
path : "/customer",
component : AsCus,
routes : [
{
path : "",
component : AsOver,
exact: true
},
{
path : "/customer/cards",
component : AsCards,
exact: true
}
]
}
];
【问题讨论】:
标签: reactjs react-router-v4 react-router-dom react-router-component