Reputation: 1
I am working on a React project in which I use the Switch, Link and Route from react-router-dom to route to the paths. but now I'm facing an issue and in console I'm getting errors The context router
is marked as required in Link
, but its value is undefined
and cannot read property history of undefined which is pointing to Link.js line number 76 . When i checked Link.js, there is a line where this.context.router.history is used, and seems like this.context.router is undefined. Couldn't figure out whats the real issue as this was working till yesterday. The version of react-router-dom I'm using is 4.1.1.
Upvotes: 0
Views: 333
Reputation: 713
Can you provide some code example? It seems like you are putting outside of BrowserRouter's scope (or HashRouter's). must always be inside the scope of .
You can do this:
<BrowserRouter>
<Link ... />
<Layout>
<Switch>
<Route ... />
<Route ... />
<Route component={NotFound} />
</Switch>
</Layout>
</BrowserRouter>`
But you cannot do something like this:
<Link ... />
<BrowserRouter>
<Layout>
<Switch>
<Route ... />
<Route ... />
<Route component={NotFound} />
</Switch>
</Layout>
</BrowserRouter>`
User Kishan Jaiswal is pointing you in the right direction by the way, he's linking to an issue which wasn't a bug but only a misplaced Link component outside of react-router-dom Router.
Upvotes: 1
Reputation: 664
just take a reference of this and match your route file https://github.com/ReactTraining/react-router/issues/4759
Upvotes: 0