动态id传参获取:
<Switch>
<Route path="/types/info/:id" component={Info}/>
</Switch>
详情页获取参数:
import React, { Component } from 'react';
class Info extends Component {
state = {
data:[],
}
componentDidMount(){
let { match } = this.props
let str = match.params.id
this.fn(str)
}
componentWillReceiveProps(nextProps){
this.fn(nextProps.match.params.id)
}
fn = (id) =>{
this.setState({
data:id
})
}
render() {
let { data } = this.state
return (
<div className="Info">
{data }
</div>
);
}
}