Programmatically navigate in react-router whilst hiding query string parameters
Note the second argument takes an object of parameters. Use the following inside your component:
this.context.transitionTo("route", { search: this.state.search, type: this.state.type });
We need to use the class based component syntax to have access to the this keyword.For example:
import React from 'react';
export default class CustomLink extends React.Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick(e) {
e.preventDefault();
this.context.router.transitionTo("route", { search: this.state.search, type: this.state.type });
}
render(){
return (<div onClick={this.handleClick}>Click</div>);
}
}
customLink.contextTypes = {
router: React.PropTypes.func.isRequired
};