跳转链接
this.props.history.push({ pathname: ‘/account‘, search: `?tab=${netflix}&id=18` })
<Link to={{ pathname: "/account", search: "?tab=b2&id=18" }}> Netflix </Link>
事例 本人使用的是react 普通函数 props
url= project/projectItem/detail/plan/planItem?tab=b6&id=9974
在props 中有 location.search获取到的是 ?tab=b6&id=9974
截取方法过于麻烦,在没有query的时候,可以
const params=new URLSearchParams(location.search); //问号后的全部参数 ?tab=b6&id=9974
// console.log(params);
/*URLSearchParams {}__proto__:
URLSearchParamsappend: ? append()
delete: ? delete()
entries: ? entries()
forEach: ? forEach()
get: ? ()
getAll: ? getAll()
has: ? has()
keys: ? keys()
set: ? ()
sort: ? sort()
toString: ? toString()
values: ? values()
constructor: ? URLSearchParams()
Symbol(Symbol.iterator): ? entries()
Symbol(Symbol.toStringTag): "URLSearchParams"
__proto__: Object*/
params.get(‘tab‘);// 放入要获取的字符串,即可获取对应的值;
new URLSearchParams()
原文:https://www.cnblogs.com/fyh0912/p/14713487.html