Javascript 使用路由器按路径传递参数,但未正确渲染
我在React中遇到了问题,在路由器中使用path传递id参数。 这是我的代码(index.js): 编辑,这是Home.jsx中的渲染函数:Javascript 使用路由器按路径传递参数,但未正确渲染,javascript,reactjs,react-router-v4,react-props,Javascript,Reactjs,React Router V4,React Props,我在React中遇到了问题,在路由器中使用path传递id参数。 这是我的代码(index.js): 编辑,这是Home.jsx中的渲染函数: render() { const { activeItem } = this.state; return( <div> <div> <MenuExampleSecondaryPointing/> </div> <div>
render() {
const { activeItem } = this.state;
return(
<div>
<div>
<MenuExampleSecondaryPointing/>
</div>
<div>
{this.props.children}
</div>
</div>
);
}
render(){
const{activeItem}=this.state;
返回(
{this.props.children}
);
}
我从一位朋友那里找到了一个答案,就这么简单:
“axios.get(“db.json”)应该是“axios.get”(“/db.json”)”
因为使用“/”我在所有目录中搜索该文件您是否尝试将精确路径=添加到第二个路径?我现在尝试了,没有帮助:/I忘记了,这是我在Home.jsx:render()中的render函数{const{activeItem}=this.state;return({this.props.children});}
render() {
const { activeItem } = this.state;
return (
<Grid>
<Grid.Column width={4}>
<Menu fluid vertical tabular>
<Menu.Item name='mail1' active={activeItem === 'mail1'} onClick={this.handleItemClick}> {this.props.match.params.id}</Menu.Item>
</Menu>
</Grid.Column>
<Grid.Column stretched width={12}>
<div>
<Segment>
{this.state.mails.length > 0 && this.state.mails ? this.state.mails[0].name : null}
</Segment>
</div>
</Grid.Column>
</Grid>
)
}
componentDidMount(){
axios.get("db.json")
.then( (response) => {
console.log(response);
this.setState({
mails: response.data.mail,
total: response.data.mail.length
});
})
.catch(function (error) {
console.log('error');
console.log(error);
});
}
render() {
const { activeItem } = this.state;
return(
<div>
<div>
<MenuExampleSecondaryPointing/>
</div>
<div>
{this.props.children}
</div>
</div>
);
}