javascript - 来自路线的参数
问题描述
我希望从 JSON 映射路径值。路径值将具有需要从 JSON 加载的页面名称。
<Switch>
<Route
render={({ location }) => {
const {pathname} = location;
const pathvalue = {pathname}
return (
<>
<div>
</div>
<div className="container">
{
data.pathvalue.map((rows, i) => { //Instead of telling the page name, I stored the page name in pathvalue const. Is it possible?
return (
<div key={i} className="row">
{rows.row.map((component, i) => {
解决方案
该<Router />
组件只需要一个子组件。您可以在此处的文档中看到它
export default function Nav() {
return (
<Router>
<Switch>
<Route
render={({ location }) => {
const { pathname } = location;
return <div>{pathname}</div>;
}}
/>
</Switch>
</Router>
);
}
然后,您可以将组件包含在<nav />
组件之外<Router />
,也可以包含一个<div />
内部,同时包含两者。
推荐阅读
- java - 如何在 router.route("/api/*").handler 中使用协程?
- ios - 在 NSFetchedResultsController 中对部分进行排序
- python - python pygalmesh 无法使工作示例
- android - Flutter 如何在我的应用程序中使用电话密码
- python-3.x - 为什么代码只匹配第一个和最后一个匹配而不是全部?
- python - 无法在类型为 UINT8 的 TensorFlowLite 张量和类型为 Java 的对象之间转换
- python - Python teampeak3 api
- java - Java NativeKeyListener 在另一个应用程序中不起作用
- javascript - JavaScript el.animate() 中的奇怪翻译
- reactjs - 未处理的运行时错误 TypeError:formData.set 不是函数?无法修复