[英]how to get url's dynamic title http://localhost:4300/title/örange which contain ö
I am getting data from backend using URL and my URL is我正在使用 URL 从后端获取数据,而我的 URL 是
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-%C3%B6range i am getting title in react as this我在 URL 中显示的博客标题,我的一个用户给出这样的标题 => my-örange,当我从 URL 获取标题时,我得到的标题是 my-%C3%B6range
let { title } = this.props.match.params;
console.log(title) // output => my-%C3%B6rang
//i want output my-örange
so how to get same string?那么如何获得相同的字符串?
You can use react-router useParams instead (from version v5.1):您可以使用 react-router useParams 代替(从版本 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和 URL 应该是 http://localhost:4300/blog/örange
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.