1.路由表配置:參數地址欄顯示
<Route path="/list/:id" component={List} />
html:<Link to='/list/2' >跳轉列表頁面</Link>
Js: this.props.history.push('/list/2');
List頁面接收:
console.log(this.props.match.params.id)//傳遞過來的所有參數
2.query方法:參數地址欄不顯示,刷新地址欄,參數丟失
html:
<Link to={{ pathname: '/list', query: { name: 'xlf' } }}>跳轉列表頁面</Link>
Js方式:this.props.history.push({ pathname: '/list', query: { name: ' sunny' } })
List頁面接收:
console.log(this.props.location.query.name)//傳遞過來的所有參數
3.state方法:參數地址欄不顯示,刷新地址欄,參數不丟失
Html: <Link to={{ pathname: '/list', state: { name: 'xlf' } }}>跳轉列表頁面</Link>
js:this.props.history.push({ pathname: '/list', state: { name: 'sunny' } })
List頁面接收
console.log(this.props.location.state.name)//傳遞過來的所有參數