Skip to content

Instantly share code, notes, and snippets.

@Nilanth
Last active August 5, 2021 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nilanth/2e7a15fea2b3b89e964177e6fdcd4708 to your computer and use it in GitHub Desktop.
Save Nilanth/2e7a15fea2b3b89e964177e6fdcd4708 to your computer and use it in GitHub Desktop.
ProtectedRoutes
import { Suspense } from 'react';
import { Route, Switch } from 'react-router-dom';
import routes from 'routes'; // Route list
import Loader from 'sharedComponent/Loader';
const ProtectedRoutes = () => (
<Switch>
<Suspense
fallback={<Loader />}
>
{routes.map(({ component: Component, path, exact }) => (
<Route
path={`/${path}`}
key={path}
exact={exact}
>
<Component />
</Route>
))}
</Suspense>
</Switch>
);
export default ProtectedRoutes;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment