Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { push, replace } from 'connected-react-router';
- export default store => next => action => {
- if (action.pushToUrl) {
- const state = store.getState();
- const currentQueries = new URLSearchParams(state.router.location.search);
- Object.entries(action.pushToUrl).forEach(([key, value]) => {
- currentQueries.set(key, value);
- });
- const queriesAsString = currentQueries.toString();
- store.dispatch(push(
- `${state.router.location.pathname}?${queriesAsString}`,
- ));
- }
- if (action.updateUrl) {
- store.dispatch(push(action.updateUrl));
- }
- if (action.replaceUrl) {
- store.dispatch(replace(action.replaceUrl));
- }
- return next(action);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement