【发布时间】:2019-07-14 12:05:13
【问题描述】:
在 Reactjs 中,当我们使用 React Router 作为页面浏览的管理器时,我们会收到 location 对象作为道具之一:
<Route path="/search" render={(props) => ( <SearchPage {...props} /> )} exact />
然后从组件内部(这里以SearchPage为例)可以通过以下方式获取路径:
var currentPathname = this.props.location.pathname;
console.log("Current pathname is: " + currentPathname);
输出:
Current pathname is: /search
但是我们是否有一个存在 searchText 请求参数的模式,例如:
/search?searchText=NissanSilvia
那么 this.props.location.pathname 仍然只会产生:
/search
如何获得包含所有当前请求参数的完整路径?
【问题讨论】:
标签: javascript reactjs routing react-router