Tutorial error step - Adding Links in the Navbar - step import { LinkContainer } from "react-router-bootstrap";

Hi all , i love the Tutorals and have been teaching me to much, but once i got to
Adding Links in the Navbar - step import { LinkContainer } from “react-router-bootstrap”;

and do npm start all i get is a website with errors

TypeError: Cannot read property ‘history’ of undefined



there is more if you need them i would really like to continue :slight_smile:

I had the same issue, it comes from a change in react-router-dom.
To get around it import withRouter from react-router-dom, and use it to wrap the LinkContainer components.

So I created a separate component in RoutedLinkContainer.js.

import React from "react";
import { LinkContainer } from "react-router-bootstrap";
import { NavItem } from "react-bootstrap";
import { withRouter } from "react-router-dom";

function RoutedLinkContainer(props) {
  return (
    <LinkContainer to={props.link}>

export default withRouter(RoutedLinkContainer);

In App.js import RoutedLinkContainer at the top, and replace the lines:

    <LinkContainer to="/signup"><NavItem>Signup</NavItem></LinkContainer>
    <LinkContainer to="/login"><NavItem>Login</NavItem></LinkContainer>


    <RoutedLinkContainer link="/signup" displayText="Signup" />
    <RoutedLinkContainer link="/login" displayText="Login" />
1 Like

Thanks for helping out @pete!

It looks like the react-router-bootstrap guys are going to push out a fix for this soon - https://github.com/react-bootstrap/react-router-bootstrap/pull/248.

For now I edited the guide to stick to react-router 4.3.1 while a fix is rolled out.