0

I have this code:

render() {
    return (
        <BrowserRouter>
            <React.Fragment>
                <Navbar inverse collapseOnSelect>
                    <Nav className='float_right'>
                        <React.Fragment>
                            <LinkContainer to='/about'>
                                <NavItem>
                                    About us
                                </NavItem>
                            </LinkContainer>
                        </React.Fragment>
                    </Nav>
                </Navbar>
                <Switch>
                    <Route exact path='/about' component={AboutComponent}/>
                    <Route exact path='/' component={HomeComponent}/>
                </Switch>
            </React.Fragment>
        </BrowserRouter>
    );
}

And I'm trying to make a simple navigation. But I'm getting an error saying:

TypeError: this.context.router is undefined

Why is that? I checked the docs and searched for the answer, but all I found was to add something with the context to the constructor, like

constructor(props,context){
    super(props,context);
}

This started happening when I added <LinkContainer/> to the code

Which just didn't work. Any ideas how to solve this?

Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400
Alex Ironside
  • 4,658
  • 11
  • 59
  • 119

0 Answers0