如何重定向到另一个页面时,按钮点击React js?



我正在制作一个带有报告按钮的谷歌地图,我不知道如何使页面重定向到另一个页面,当带有类"report-btn"点击?我试着使用,但它没有工作,我不知道如何去实现这个

export class MapContainer extends Component {
state = {
showingInfoWindow: false,
activeMarker: {}, 
selectedPlace: {}, 
};
onMarkerClick = (props, marker, e) =>
this.setState({
selectedPlace: props,
activeMarker: marker,
showingInfoWindow: true,
});
onClose = (props) => {
if (this.state.showingInfoWindow) {
this.setState({
showingInfoWindow: false,
activeMarker: null,
});
}
};
render() {
return (
<Map
google={this.props.google}
zoom={14}
style={mapStyles}
initialCenter={{
lat: 40.75901,
lng: -73.984474,
}}
>
<Marker onClick={this.onMarkerClick} name={"S Train - 42 Street"} />
<InfoWindow
marker={this.state.activeMarker}
visible={this.state.showingInfoWindow}
onClose={this.onClose}
>
<div>
<h4>{this.state.selectedPlace.name}</h4>
<button className="report-btn">Report</button>
</div>
</InfoWindow>
</Map>
);
}
}

您有2 solutions,使用react-router-domwindow.location.href/replace

import { Link, NavLink } from 'react-router-dom';

你应该使用

import { Link} from 'react-router-dom';

return (
<Link to={"/somewhereyoulike}>
<Button>
somthiong
</Button>
</Link>
)

最新更新