I'm looking for some information on the best approach to url encode text client side before it's passed to an api call.
I have a text box that takes a word or multiple words from the user. A button is clicked which takes the text and passes it as a param into a api call.
If a user includes a slash in the text, such as desk / table this errors out as the forward slash isn't encoded and it essentially breaks the endpoint.
Example
https://www.example.com/search/desk%20/%20table
I wan't to encode the the forward clash so it's not seen as an additional path. Whats the correct way to do this. Would it be using encodeURIComponent.