Skip to content

Custom Query Parameters in URL #6278

Answered by Haroenv
joshpalmeroc asked this question in Q&A
Discussion options

You must be logged in to vote

What I recommend is the following:

  1. non-InstantSearch parameters should always stay in the URL
  2. non-InstantSearch URL updates should be done separately
const routing = {
  stateMapping: {
    stateToRoute(uiState) {
      const existingParameters = new URLSearchParams(window.location.search);

      return {
        ...uiState['example'],
        JobPostingTitle: existingParameters.get('JobPostingTitle'),
        Location: existingParameters.get('Location'),
      };
    },
    routeToState({ JobPostingTitle, Location, ...routeState }) {
      return {
        ['example']: routeState,
      };
    },
  },
};

Then later when you update the JobPosting or Location, you can do history.pushState

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by joshpalmeroc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants