[英]React Router - get URL params outside of page component (inside of layout footer)
I'm writing an app using React and trying to make a dynamic footer - I have a URL there that varies between pages 我正在使用React编写一个应用程序,并试图创建一个动态页脚-我的URL在页面之间有所不同
Is there any way to get URL params outside of page component somehow without copying footer to each page? 有什么办法可以在不将页脚复制到每个页面的情况下以某种方式在页面组件之外获取URL参数?
Are you using React Router? 您在使用React Router吗? React Router v4+ contains a url query param.
React Router v4 +包含url查询参数。
const params = new URLSearchParams(this.props.location.search);
const foo = params.get('foo'); // bar
You can alternatively use window.location.hash
您也可以使用
window.location.hash
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.