禮貌爲[Tharaka Wijebandara]解決這個問題是: 具有集裝箱部件提供選擇組分與具有至少做就集裝箱以下回調函數:
props.history.push(Selection coming from Selection
);
請看以下集裝箱(稱爲Geoselector)成分的例子,通過定義的setLocation回調下降到選擇(稱爲Geosuggest)組件。
class Geoselector extends Component {
constructor (props) {
super(props);
this.setLocation = this.setLocation.bind(this);
//Sets location in case of a reload instead of entering via landing
if (!Session.get('selectedLocation')) {
let myRe = new RegExp('/location/(.*)');
let locationFromPath = myRe.exec(this.props.location.pathname)[1];
Session.set('selectedLocation',locationFromPath);
}
}
setLocation(value) {
const newLocation = value.label;
if (Session.get('selectedLocation') != newLocation) {
Session.set('selectedLocation',newLocation);
Session.set('locationLngLat',value.location);
this.props.history.push(`/location/${newLocation}`)
};
}
render() {
return (
<Geosuggest
onSuggestSelect={this.setLocation}
types={['(cities)']}
placeholder="Please select a location ..."
/>
)
}
}