Created
June 6, 2021 09:57
-
-
Save yushanwebdev/e6b4d2f7c8c3fed95f9adb563f48125a to your computer and use it in GitHub Desktop.
React Router code to persist the global components in all the pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const routes = [ | |
{ path: '/one', | |
component: One | |
}, | |
{ path: '/two', | |
component: Two | |
}, | |
{ path: '/three', | |
component: Three | |
} | |
] | |
<Router> | |
<div> | |
<Switch> | |
{routes.map(route => ( | |
<Route path={route.path} component={Header}/> | |
))} | |
</Switch> | |
<Switch> | |
{routes.map(route => ( | |
<Route path={route.path} component={Sidebar}/> | |
))} | |
</Switch> | |
<Switch> | |
{routes.map(route => ( | |
<Route path={route.path} component={route.component}/> | |
))} | |
<Route component={NoMatch}/> | |
</Switch> | |
</div> | |
</Router> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found this useful information while research an answer for this StackOverflow question.
Useful Resources :-