路由跳轉this.props.history.push('');
export default class IndexView extends React.Component {
route = () => {
this.props.history.push('/my/login',{
data:111
});
console.log("跳轉成功!");
}
render() {
return (
<div>
<Contextmy></Contextmy>
<input type = "button" onClick = {() => {this.route()}} value = "登入"/>
</div>
)
}
}
/my/login.jsx頁面:
render() {
console.log(this.props.location.state.data);
return (
<div>
<p>歡迎登入</p>
</div>
)
}
列印結果: