//value push from /status -> /schedule/:selfUri
getSchedule = e => {
e.preventDefault();
this.props.history.push(`/schedule/${this.state.selfUri}`)
}
// router-container
<Router>
<Route path="/status" component={Status} exact />
<Route path="/schedule/:selfUri" component={Schedule}/>
</Router>
// link-container
<Link to="/schedule/selfUri">Schedule</Link>
//Schedule component
class Schedule extends React.Component {
componentDidMount() {
const { selfUri } = this.props.match.params;
console.log(selfUri)
axios({
method: 'get',
url: `${selfUri}`
与其尝试将值推入/schedule
,而是尝试加载网址/schedule//value/of/selfUri
我只想在/schedule
获得selfUri的值。
//Using localStorage I can do
getSchedule = e => {
e.preventDefault();
localStorage.setItem('selfUri', this.state.selfUri);
this.props.history.push(`/schedule`)
// this.props.history.push(`/schedule/${this.state.selfUri}`)
}
//Then from /schedule path
componentDidMount() {
// const { match: { params: { selfUri }}} = this.props;
// console.log(this.props.match.params)
var selfUri = localStorage.getItem('selfUri')
console.log(selfUri)
axios({
method: 'get',
url: `${selfUri}`,
})