首页 > 解决方案 > 如何使用浏览器的后退按钮获取上一个搜索页面

问题描述

我有一个搜索页面,它重定向到search results page使用以下逻辑

 <input id="search" type="search" placeholder="search ..." className="osLight english" name="query"
            onChange={this.handleChange}
          />
          {
            this.state.searchProperties.length > 0 &&
            <Redirect to={{
              pathname: '/search',
              results: this.state.searchProperties
            }} />
          }

现在...在搜索结果中,我可以单击并转到其中一种产品

const properties = this.props.location.results;
<div className="col-xs-12 col-sm-12 col-md-6 col-lg-6 arabic-english">
     <Link className="card" to={{
         pathname: "/" + property.property_id,
         property: property
     }}
     >
...
    </Link>
</div>

但是现在当我在浏览器中按回时我会进入一个空白search result page,我如何保持搜索结果状态以便在我按回时被查看?

标签: reactjs

解决方案


@Exorcismus 您可以使用历史对象和查询字符串来获取搜索结果。

请找到“ React JS - 使用后退按钮获取以前的搜索”作为可以帮助您的链接。

如果这没有帮助,请恢复。


推荐阅读