Home > OS >  fetch title value with punctuation using useParams in react
fetch title value with punctuation using useParams in react

Time:04-18

I want to fetch the title value from the URL. But the problem is title value contains punctuation. For example: "Who's Available? [April 2022]". useParams can't fetch the full title from the URL.

How can I fetch this full title name from the URL?

CodePudding user response:

When adding the title value in the URL, it needs to be URL Encoded in order for useParams to correctly read it.

In your example it whould be

url.com/?title=Who's Available? [April 2022]

When setting it from code you can achieve it by using URLSearchParams or libraries like qs to encode your strings

  • Related