I’m developing a simple app in React, and I have an error adding the Link
component from the react-router-dom
package. The component that contains the routes is App.js
, which is composed as follows:
In the <Header />
component, is grafted <MenuNavigation />
composed as follows:
This is where the error occurs:
2
Answers
Try setting your router like this and remove the trailing
/
from the paths;You are rendering the
Link
component outside any routing context, i.e. theRouterProvider
component.Create a layout route component that renders
Header
andFooter
, and anOutlet
for the nested children routes.Example: