Skip to content
Advertisement

Mutliple components rendered in React JS using Router

I have tried using <Switch> and exact after viewing this post: React Router v4 renders multiple routes but it hasn’t resolved my problem, which is that 2 of my components are rendered at the same time when the <Link> function operates.

The code:

JavaScript

The result is the html of Component A showing up and “Welcome to ComponentB” underneath them. Please help me out with this reaact-router issue

Advertisement

Answer

Contents of ComponentA shows up because ComponentB is now a child route of ComponentA. To render them separately, need a parent component like this:

JavaScript

Edit focused-neumann-mm8qb

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement