路由器组件与终极版连接后反应路由器DOM不会重新渲染

问题描述 投票:0回答:1

出于某种原因,我以后在使用connect()代码连接我的路线组成部分 - 我的组件单击它们之后导致重新渲染。有人可以帮助解释什么是错的代码?评论我们的连接功能后,点击我的按钮会重新渲染。我删除了我的import语句,以减少代码量。

// List of routes that uses the page layout
// listed here to Switch between layouts
// depending on the current pathname
const listofPages = [
    /* See full project for reference */
];

class Routes extends React.Component {

    constructor(props){
        super(props);
        this.state = {
            hideNavigation: false
        };
    };

    toggleHeader = () => {
        const { hideNavigation } = this.state
        this.setState({ hideNavigation: !hideNavigation  })
    };

    render(){
        const currentKey = this.props.location.pathname.split('/')[1] || '/';
        const timeout = { enter: 500, exit: 500 };

        // Animations supported
        //      'rag-fadeIn'
        //      'rag-fadeInRight'
        //      'rag-fadeInLeft'

        const animationName = 'rag-fadeIn'
        return (
            // Layout component wrapper
            // Use <BaseHorizontal> to change layout
            <Base hideNavigation={this.state.hideNavigation}>
              <TransitionGroup>
                <CSSTransition key={currentKey} timeout={timeout} classNames={animationName} exit={false}>
                    <div>
                        <Suspense fallback={<PageLoader/>}>
                            <Switch location={this.props.location}>

                                <Route 
                                    loggedIn={this.props.isLoggedIn}
                                    path="/login" 
                                    render={() => (<Login toggleHeader={this.toggleHeader} />)}
                                />

                                <PrivateRoute 
                                    loggedIn={this.props.isLoggedIn}
                                    path="/my-credentials" 
                                    component={MyCredentials}
                                />

                                <PrivateRoute 
                                    loggedIn={this.props.isLoggedIn}
                                    path="/submenu" 
                                    component={SubMenu}
                                />

                                <PrivateRoute 
                                    loggedIn={this.props.isLoggedIn} 
                                    path="/new-application" 
                                    toggleHeader={this.toggleHeader}
                                    component={NewApplication}
                                />

                                { this.props.isLoggedIn ? 
                                    <Redirect to="/submenu"/> : 
                                    <Redirect to="/login"/>
                                }

                            </Switch>
                        </Suspense>
                    </div>
                </CSSTransition>
              </TransitionGroup>
            </Base>
        )
    }
}

const mapStateToProps = (state) => {
    console.log(state)
    return {
        "isLoggedIn": state.auth.isLoggedIn
    }
}

const mapDispatchToProps = dispatch => ({ })

export default connect(
    mapStateToProps,
    mapDispatchToProps
)(withRouter(Routes));
reactjs
1个回答
1
投票

更改肝卵圆细胞的顺序。所以变化

export default connect(mapStateToProps, mapDispatchToProps(withRouter(Routes));

export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Routes));
© www.soinside.com 2019 - 2024. All rights reserved.