Skip to content

Modal displays whenever any query string is added to the URL #163

@AdamJHall

Description

@AdamJHall

Hello,

We're currently using this library a project and ran into an issue where the search modal would be displayed whenever any query string was added to the URL. This was an issue as any user coming from a marketing email, or google ad would immediately have the search modal pop up.

Our current workaround has been to update the getStateFromUrl function in router.js to filter out any query parameters it shouldn't care about e.g.

export const getStateFromUrl = ({ search }) => {
  let filteredQuery = {};
  if (search) {
    // allowedQueryParams are the only values passed back to the Algolia model
    const allowedQueryParams = [
      'query',
      'refinementList',
      'range',
      'page'
    ];
    const queryString = qs.parse(search.slice(1));
    filteredQuery = Object.fromEntries(
      Object.entries(queryString).filter(([key]) =>
        allowedQueryParams.includes(key)
      )
    );
  }
  return filteredQuery;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions