i am getting data data from backend using url and my url is
http://localhost:4300/title/örange
the title of blog i am showing in url and one of my user give title like this => my-örange and when i am fetching title from url i am getting title as my-örange i am getting title in react as this
let { title } = this.props.match.params;
console.log(title) // output => my-örang
//i want output my-örange
so how to get same string?
CodePudding user response:
You should use decodeURIComponent(). Read more on it here. Example:
let { title } = decodeURIComponent(this.props.match.params);
console.log(title) // output => my-örange
CodePudding user response:
You can use react-router useParams instead (from version v5.1):
import { useParams } from "react-router-dom"
const params = useParams()
console.log(params.title)
the route:
<Route path="blog/:title" element={<Blog />} />
and the URL should be http://localhost:4300/blog/örange
