链接需要按下两次,React Router v4

时间:2018-06-20 14:16:33

标签: reactjs react-router react-redux

我有一张卡片列表,当我按下它们时,只有网址会更改。

路由由baseUrl +更改的ID组成。

我尝试了以下解决方案:

  • Adding withRouter and having the 'exact' tag on the route
  • I don't use dispatch, is a different type of problem
  • Or from the documentation of block components,我将位置信息传递给了可能阻止更改的所有候选人。

    class Main extends Component {
        constructor(props) {
            super(props);
        }
    
    render() {
        const { results, fetchState, location } = this.props;
        return (
            <Strip location={location}>
                {
                    results.length > 0 ?
                        <div location={location}>
                            <Sort />
                            {
                                results.map((result, i) =>
                                    <div key={i} location={location}>
                                        <Card to={urls.profile.base + '/' + result._id || 'unknown'}  result={result} _id={result._id}  />
                                        <Seperator />
                                    </div>
                                )}
                        </div>
                        :
                        <Flex>
                            {
                                fetchState === 'pending' ?
                                    <Loader /> :
                                    <div style={{ textAlign: 'center' }}>  No result found  </div>
                            }
                        </Flex>
    
                }
            </Strip>
    
    
              );
        }
    

    }          使用Router导出默认值(connect(mapStateToProps,mapDispatchToProps)(Main));

和卡组件:

const Card = (props) => {
    const { result, _id } = props;
    return (
        <Resp.desktop>
            {
                (matches) =>
                    <Element  mobile={!matches} >
                        <Name company={result.company} />
                        {matches ?
                            <Info services={result.services} company={result.company} />
                            :
                            <Info company={result.company} />
                        }
                        {matches && <Pictures />}
                    </Element>
            }
        </Resp.desktop>
    );
}

有人知道如何解决吗?

谢谢!

0 个答案:

没有答案