刷新相同的组件而不重定向

时间:2018-04-05 10:33:28

标签: reactjs react-router

我有一个搜索组件,我将其重定向到搜索结果页面。搜索组件位于nav-bar中,并在包含搜索结果页面的每个页面中呈现。现在我使用react-router重定向到结果页面,我的代码如下所示。 (我只发布渲染功能)

<FormGroup className={this.props.className}>
    <FormControl key='search' id='search' type='text' placeholder='Search Packages' value={this.state.searchKey} onKeyDown={this.handleKeyPress} onChange={this.handleOnSearchValChange} />
    <i className='glyphicon glyphicon-search form-control-feedback' /> {this.state.searchResults.length > 0 &&
    <Redirect to={{ pathname: '/search', searchResults: this.state.searchResults, }}/> }
</FormGroup>

这在每个页面都很有效,但是当我尝试搜索与redirect组件在同一路径时,我在控制台中收到错误,如下所示。

You tried to redirect to the same route you're currently on: "/search"

我明白在同一条路径上没有重定向点,所以我的问题是,如何以更专业的方式编写这段代码?

0 个答案:

没有答案