【发布时间】:2020-10-14 15:12:14
【问题描述】:
我的组件中有一个搜索栏。我想点击搜索,它应该调用搜索操作并将结果导航到父组件。
<input
onKeyPress={(event) => {
if (event.key === "Enter") {
this.onSearch(event.target.value);
}
}}
type="text"
/>
方法:
onSearch(searchString) {
// perform Search
this.props.history.push("/details");
}
我希望它使用搜索字符串导航到详细信息页面,在 URL 中我期望类似:
http://localhost:8080/details?search="searchString".
谁能帮我解决这个问题?
【问题讨论】:
-
您好,我的回答解决了您的问题吗?
-
是的,但预计每当用户为搜索结果添加书签时,他应该在激活搜索选项的情况下登陆同一页面。你能帮我解决一下吗
-
您可以在渲染 /details 页面的组件的 componentDidMount 方法中处理此问题:您可以检查查询参数是否存在并进行处理。希望这会有所帮助
标签: javascript reactjs typescript input routes