Skip to content

connect prevents LinkContainer from marking links as active #388

Closed
@olalonde

Description

@olalonde

Took me a while to figure this one out. For some strange reason, when I use connect to decorate my component, <LinkContainer> stops marking links as active. If I remove the connect()(Header) call, <LinkContainer> works as expected.

import React from 'react'
import { connect } from 'react-redux'
import { LinkContainer } from 'react-router-bootstrap'
import {
  Nav,
  Navbar,
  NavItem,
} from 'react-bootstrap'

class Header extends React.Component {
  render() {
    return (
      <div>
        <Navbar>
          <Navbar.Collapse>
            <Nav pullLeft>
              <LinkContainer to="/dashboard/registrations">
                <NavItem>
                  Registrations
                </NavItem>
              </LinkContainer>
              <LinkContainer to="/dashboard/monitoring">
                <NavItem>
                  Monitoring
                </NavItem>
              </LinkContainer>
            </Nav>
          </Navbar.Collapse>
        </Navbar>
      </div>
    )
  }
}

export default Header

/*
When using connect(), LinkContainer stops working and
links are no longer marked as active when URL changes
*/

// export default connect()(Header)

Here's the behaviour I get when using connect:

gif

Thinks those are related but I can't figure out a quick/official fix:

remix-run/react-router#3286
remix-run/react-router#470

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions