location.ts 683 B

1234567891011121314151617181920212223242526
  1. import { Action } from 'app/core/actions/location';
  2. import { LocationState } from 'app/types';
  3. import { renderUrl } from 'app/core/utils/url';
  4. export const initialState: LocationState = {
  5. url: '',
  6. path: '',
  7. query: {},
  8. routeParams: {},
  9. };
  10. export const locationReducer = (state = initialState, action: Action): LocationState => {
  11. switch (action.type) {
  12. case 'UPDATE_LOCATION': {
  13. const { path, query, routeParams } = action.payload;
  14. return {
  15. url: renderUrl(path || state.path, query),
  16. path: path || state.path,
  17. query: query || state.query,
  18. routeParams: routeParams || state.routeParams,
  19. };
  20. }
  21. }
  22. return state;
  23. };