Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import { push, replace } from 'connected-react-router';
  2.  
  3. export default store => next => action => {
  4. if (action.pushToUrl) {
  5. const state = store.getState();
  6.  
  7. const currentQueries = new URLSearchParams(state.router.location.search);
  8. Object.entries(action.pushToUrl).forEach(([key, value]) => {
  9. currentQueries.set(key, value);
  10. });
  11.  
  12. const queriesAsString = currentQueries.toString();
  13.  
  14. store.dispatch(push(
  15. `${state.router.location.pathname}?${queriesAsString}`,
  16. ));
  17. }
  18.  
  19. if (action.updateUrl) {
  20. store.dispatch(push(action.updateUrl));
  21. }
  22.  
  23. if (action.replaceUrl) {
  24. store.dispatch(replace(action.replaceUrl));
  25. }
  26.  
  27. return next(action);
  28. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement