Have created a react js dashboard app with the following versions "react-router": "^6.0.0-beta.0", "react-router-dom": "^6.0.0-beta.0"
have to implement a protected routing instance for the app, as of react router v6 above protected routing is a bit different than i'm used to on v5. could someone show me how to add protected routing for this? Thank you for your time!
here's the app.js
import 'react-perfect-scrollbar/dist/css/styles.css';
import React from 'react';
import { useRoutes } from 'react-router-dom';
import { ThemeProvider } from '@material-ui/core';
import GlobalStyles from 'src/components/GlobalStyles';
import 'src/mixins/chartjs';
import theme from 'src/theme';
import routes from 'src/routes';
const App = () => {
const routing = useRoutes(routes);
return (
<ThemeProvider theme={theme}>
<GlobalStyles />
{routing}
</ThemeProvider>
);
};
export default App;
and here is the route.js code
const routes = [
{
path: 'app',
element: <DashboardLayout />,
children: [
{ path: 'account', element: <AccountView /> },
{ path: 'reporting', element: <CustomerListView /> },
{ path: 'dashboard', element: <DashboardView /> },
{ path: 'classrooms', element: <ProductListView /> },
{ path: 'settings', element: <SettingsView /> },
{ path: '*', element: <Navigate to="/404" /> }
]
},
{
path: '/',
element: <MainLayout />,
children: [
{ path: 'login', element: <LoginView /> },
{ path: 'register', element: <RegisterView /> },
{
path: 'RegisterViewContactDetails',
element: <RegisterViewContactDetails />
},
{ path: 'ForgotPassword', element: <ForgotPassword /> },
{ path: 'RestPassword', element: <RestPassword /> },
{ path: '404', element: <NotFoundView /> },
{ path: '/', element: <Navigate to="/login" /> },
{ path: '*', element: <Navigate to="/404" /> }
]
}
];
export default routes;