javascript - 如何正确合并 react-router-config 数组?
问题描述
我正在查看https://www.npmjs.com/package/react-router-config
我想用它来构建我的路由配置,但是我的路由配置将来自其中的多个包,node_modules
并且需要在使用前正确合并。
路由配置形状
路由是与 a 具有相同属性的对象,但<Route>
有几个不同之处:
- 它接受的唯一
render
道具是component
(否render
或children
)引入了子路由的路由键 - 消费者可以自由地将他们想要的任何其他道具添加到路由中,您可以
props.route
在组件内部访问,该对象是对用于渲染和匹配的对象的引用。 - 接受prop 以防止在从具有相同组件和相同prop
key
的路由进行转换时重新安装组件key
const routes = [
{ component: Root,
routes: [
{ path: '/',
exact: true,
component: Home
},
{ path: '/child/:id',
component: Child,
routes: [
{ path: '/child/:id/grand-child',
component: GrandChild
}
]
}
]
}
]
因此,如果我要合并第二条路线配置:
const routes = [
{ component: Root,
name: 'root',
routes: [
{ path: '/',
exact: true,
component: Home
},
{ path: '/child/:id',
name: 'childView',
routes: [
{ path: '/child/:id/related-child',
component: RelatedChild
}
]
}
]
}
]
我想与每个嵌套路由的所有键都有一个对应关系,即合并。
我怎样才能做到这一点
我怎样才能做到这一点?
解决方案
推荐阅读
- r - glm函数中的循环数据框列
- docker - 如何通过 app.json 在 Heroku 上运行 Docker Hub 容器?
- javascript - 你如何让一个函数改变在javascript中放入的变量?
- javascript - 如何将响应中的页码设置为数字,而不是 PaginationJS 中的数组
- servicestack - 列表与细节 DTO
- python - 1. 总结 pandas 数据框中的特定行 2. 创建包含整体价值的新数据框
- mysql - Azure Mysql 保持高 CPU 使用率,我无法调低它
- crystal-reports - 是否可以在 Crystal Reports 中创建列表或其他可变对象?
- android - Firebase 推送通知 - 如何更改活动目的地?
- vmware-clarity - 如何使用清晰度自定义 clrdgfilter 的位置?