Javascript 无法在react Router dom中将道具传递给路由器

Javascript 无法在react Router dom中将道具传递给路由器,javascript,reactjs,react-router-dom,react-props,Javascript,Reactjs,React Router Dom,React Props,我在尝试使用react Router dom通过路由器向组件传递道具时遇到了一些问题 经过一些搜索,我知道我必须使用带有内联函数的render方法,但是对于以下代码,我有一个错误(无法读取undefined的属性“map”)。我尝试了多种方法,但都没有成功。 唯一有效的是当我输入一个直接值(比如100或“test”)时 从“react Router dom”导入{BrowserRouter as Router,Route,Link}; 常量字符选择=道具=>{ 返回( {props.availa

我在尝试使用react Router dom通过路由器向组件传递道具时遇到了一些问题

经过一些搜索,我知道我必须使用带有内联函数的render方法,但是对于以下代码,我有一个错误(无法读取undefined的属性“map”)。我尝试了多种方法,但都没有成功。 唯一有效的是当我输入一个直接值(比如100或“test”)时

从“react Router dom”导入{BrowserRouter as Router,Route,Link};
常量字符选择=道具=>{
返回(
{props.availableCharacters.map((number,i)=>{i})
);
};
常量内容=道具=>{
返回(
阿奎尔
新党
()}/>
);
};
类应用程序扩展了React.Component{
静态可用字符=()=>[
{imgName:“base_loup.png”,name:“loup Garou”,maxInGame:4},
{imgName:“base_simple_villageois.png”,名称:“simple villageois”,maxInGame:10},
{imgName:“base_chasseur.png”,name:“chasseur”,maxInGame:1},
{imgName:“base_petite_fille.png”,名称:“petite fille”,maxInGame:1},
{imgName:“base_sorciere.png”,name:“Sorcière”,maxInGame:1},
{imgName:“base_cupidon.png”,名称:“cupidon”,maxInGame:1},
{imgName:“base_voleur.png”,名称:“voleur”,maxInGame:1},
{imgName:“base_voyante.png”,名称:“voyante”,maxInGame:1}
];
render(){
返回(
);
}
}
const rootElement=document.getElementById(“根”);
render(,rootElement);

非常感谢您的帮助。

您是否尝试重命名渲染路由的props arg,以查看是否与
const Content=props=>{

<Route path="/charactersSelection" render={p => (<CharactersSelection {...props} />)}/>
()}/>
事实上,我认为你也不需要arg道具:

<Route path="/charactersSelection" render={() => (<CharactersSelection {...props} />)}/>
()}/>

应能工作

从阵列数据中删除静态数据,且无需输入函数, 见示例:

从“React”导入React;
从“react dom”导入react dom;
从“react Router dom”导入{BrowserRouter as Router,Route,Link};
常量字符选择=道具=>{
返回(
{props.availableCharacters.map((number,i)=>{i})
);
};
常量内容=道具=>{
返回(
{console.log(props.availableCharacters)}
阿奎尔
新党
}
/>
);
};
类应用程序扩展了React.Component{
可用字符=[
{imgName:“base_loup.png”,name:“loup Garou”,maxInGame:4},
{imgName:“base_simple_villageois.png”,名称:“simple villageois”,maxInGame:10},
{imgName:“base_chasseur.png”,name:“chasseur”,maxInGame:1},
{imgName:“base_petite_fille.png”,名称:“petite fille”,maxInGame:1},
{imgName:“base_sorciere.png”,name:“Sorcière”,maxInGame:1},
{imgName:“base_cupidon.png”,名称:“cupidon”,maxInGame:1},
{imgName:“base_voleur.png”,名称:“voleur”,maxInGame:1},
{imgName:“base_voyante.png”,名称:“voyante”,maxInGame:1}
];
render(){
返回(
);
}
}
const rootElement=document.getElementById(“根”);
render(,rootElement)
<Route path="/charactersSelection" render={() => (<CharactersSelection {...props} />)}/>