Skip to content

Instantly share code, notes, and snippets.

@yushanwebdev
Created June 6, 2021 09:57
Show Gist options
  • Save yushanwebdev/e6b4d2f7c8c3fed95f9adb563f48125a to your computer and use it in GitHub Desktop.
Save yushanwebdev/e6b4d2f7c8c3fed95f9adb563f48125a to your computer and use it in GitHub Desktop.
React Router code to persist the global components in all the pages
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>
@yushanwebdev
Copy link
Author

I found this useful information while research an answer for this StackOverflow question.

Useful Resources :-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment