An & sign can change what a link asks for
A search works with a simple word but fails when someone enters a name containing spaces, accents or an & sign. The page opens without an obvious error. It simply interprets a different query from the one the person intended.
The problem may be in how the address is built. URL parameters have a syntax: not every character in a value can be pasted directly into the query string. MDN documents URLSearchParams, a browser interface for working with these name and value pairs.
Separate the value from the syntax
Imagine a filter whose value is R+D & design. If a process concatenates it directly after q=, part of the text can become query structure. Checking that the link starts with the correct domain is not enough.
With URLSearchParams, pass the original name and value to the appropriate methods and let serialization produce the encoded query. The point is to separate data from syntax rather than handling each character with a different manual replacement.
Do not encode twice
MDN specifies that individual names and values should be supplied in their unencoded form. If you pass an already encoded value, the percent sign can be encoded again and the recipient ends up seeing different data.
The + sign also needs care. When parsing a query string, URLSearchParams interprets it as a space. When a value must preserve a literal +, add it as an original value with append or set, rather than constructing an interpolated query string. Serialization handles the distinction.
Decide whether a parameter can repeat
Adding a filter is not the same as replacing it. append adds a new pair; set sets a value and removes other values with the same name. If a search accepts several categories, this difference affects what the server receives.
Test the full journey with spaces, accents, &, + and repeated values. Do not inspect only the generated address: check what the destination reads and whether the result matches the original query.
Finally, encoding is not encryption. Parameters remain part of the address and can end up in history or logs. Do not put secrets in them simply because the text looks less readable.