Skip to content

Instantly share code, notes, and snippets.

@Nilanth

Nilanth/App.js Secret

Last active August 17, 2021 02:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nilanth/4e47b87aea7061c81cd069d25744c8d7 to your computer and use it in GitHub Desktop.
Save Nilanth/4e47b87aea7061c81cd069d25744c8d7 to your computer and use it in GitHub Desktop.
App.js file
import { lazy, Suspense } from 'react';
import {
BrowserRouter as Router,
Switch,
Route,
Redirect
} from 'react-router-dom';
import Loader from 'shareComponent/Loader';
import ProtectedRoutes from 'routes/ProtectedRoutes'; //Authenticated routes
import PublicRoute from 'routes/PublicRoute';
import PrivateRoute from 'routes/PrivateRoute';
const LoginPage = lazy(() => import('components/LoginPage'));
const Register = lazy(() => import('components/Register'));
const ForgotPassword = lazy(() => import('components/ForgotPassword'));
const NoFoundComponent = lazy(() => import('components/NoFoundComponent'));
const App = () => {
const isAuthenticated = getToken();
return (
<Router>
<Suspense fallback={<Loader />}>
<Switch>
<PublicRoute
path="/login"
isAuthenticated={isAuthenticated}
>
<LoginPage />
</PublicRoute>
<PublicRoute
path="/register"
isAuthenticated={isAuthenticated}
>
<Register />
</PublicRoute>
<PublicRoute
path="/forgot-password"
isAuthenticated={isAuthenticated}
>
<ForgotPassword />
</PublicRoute>
<PrivateRoute
path="/"
isAuthenticated={isAuthenticated}
>
<ProtectedRoutes />
</PrivateRoute>
<Route path="*">
<NoFoundComponent />
</Route>
</Switch>
</Suspense>
</Router>
);
};
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment