I am still a newbie to React. So here I am rendering the root component with two routes: Home and About located in functional components: home.js and about.js respectively. However, even after using exact attribute and , the root component keeps on rendering above. I still cannot figure out how to not render the root component when I am redirecting to any of the mentioned routes?
Heres the live demo: https://codesandbox.io/s/vmz6zwq0k7
The Route component is acting like a "placeholder" for the component you want to render when the URL matches. everything above it (parents and siblings) wont get affected.
Given this code example:
This line of code:
Is only a "placeholder" for the
Home
component. It won't render anything only when thepath
is matching"/home"
.When the
path
will match, theRoute
component will render the passed component, TheHome
component in this case.It will not affect the entire app tree, and for a good reason!
If the entire app would get re-rendered and replaced with the
Home
component you would loose the navigation links.