Reputation: 85765
I am using react router 4 and when some checkboxes are checked I want to update the current url with the values from the checkbox.
How can I push parameters to the current url? Also if possible I don't really want to support it that if they click the back button it would uncheck the last option (unless I pretty much get this functionality for free).
So I am thinking it would have to be more a replacement of the url rather that push.
Upvotes: 1
Views: 2689
Reputation: 1920
Install history
package from npm
Create a new file config/history.js
import createHistory from 'history/createBrowserHistory';
export default createHistory();
Now in your code where you wanted to update the url, use the following:
import history from './config/history';
....
<input type="checkbox" onChange={() => history.push('/foo?variable=value') } />
Upvotes: 2