浏览器访问子组件路由/parent/child, 子组件为什么接收不到参数
父组件A
路由 /parent
parent.js
const Parent = props => {
const { children } = props;
const childrenWithProps = React.Children.map(children, child => React.cloneElement(child, { a: 123 })
console.log('childrenWithProps', childrenWithProps)
// 在这里输出 childrenWithProps 中是有参数a的
return (
<div>
{childrenWithProps}
</div>
);
};
export default Parent;
子组件B
路由 /parent/child
child.js
import React from 'react';
const Child = (props) => {
console.log('Child', props, props.a)
// 这里输出props, 为什么props 里会没有属性a?
return (
<div>child</div>
)
}
export default Child;
路由文件
router.js
{
path: '/parent',
component: './Parent',
routes: [
{
path: '/parent/child',
component: './Parent/Child',
},
]
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…