How configure redux toolkit rtk query params like ASCII format?

658 Views Asked by At

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,
          },
1

There are 1 best solutions below

1
Wraithy On BEST ANSWER

You can use encodeURIComponent

const string = `api/pages/search?name=${encodeURIComponent('firstWord+secondWord')}`;
console.log(string);