I'm trying to pass a string of several words to the parameter. In endpoint, a query is formed with the parameter as "api/pages/search?name=firstWord+secondWord". And I need to get "api/pages/search?name=firstWord%20secondWord"
query: (search: string) => {
// variable search can be multiple words
return {
url: `pages/search`,
params: {
name: search,
},
You can use encodeURIComponent
const string = `api/pages/search?name=${encodeURIComponent('firstWord+secondWord')}`;
console.log(string);