React Routing

Routing

In a single-page application, you change what the user sees by showing or hiding portions of the display that correspond to particular components, rather than going out to the server to get a new page. As users perform application tasks, they need to move between the different views that you have defined

To handle the navigation from one view to the next, you use the React Router. The Router enables navigation by interpreting a browser URL as an instruction to change the view. Your complete route structure is place at main.tsx file under src » main.tsx

Suppose you want to create a new module ( For creating a new module refer create new module ) then you have to add new routes for that modules.


Basic Route

Following are the fundamental building blocks to creating a route.

Import the main.tsx into App.tsx and add it to the imports array.

 
                            import ReactDOM from 'react-dom/client'
                            import { Routedata } from "./components/common/routingdata";
                            import App from "./layouts/App";
                            import './index.scss'
                            import { HelmetProvider } from 'react-helmet-async';
                            import { BrowserRouter, Route, Routes } from 'react-router-dom';
                            import { Fragment } from 'react';
                            import Login from './container/authentication/login/login';
                            import Authenticationlayout from './layouts/authentication-layout';
                            import Register from './container/authentication/register/register';
                            import Forgotpassword from './container/authentication/forgotpassword/forgotpassword';
                            import Lockscreen from './container/authentication/lockscreen/lockscreen';
                            import Underconstruction from './container/authentication/underconstruction/underconstruction';
                            import Error400 from './container/authentication/errorpages/error400/error400';
                            import Error401 from './container/authentication/errorpages/error401/error401';
                            import Error403 from './container/authentication/errorpages/error403/error403';
                            import Error404 from './container/authentication/errorpages/error404/error404';
                            import Error500 from './container/authentication/errorpages/error500/error500';
                            import Error503 from './container/authentication/errorpages/error503/error503';
                            import Firebasesignin from './firebase/Firebasesignin';
                            import Firebasesignup from './firebase/Firebasesignup';
                            import Firebasereset from './firebase/Firebasereset';
                            
                            
                            
                            ReactDOM.createRoot(document.getElementById('root')!).render(
                             <Fragment>
                               <HelmetProvider>
                                 <BrowserRouter>
                                   <Routes>
                            
                                  //firebase authentication
                            
                                     <Route path={`${import.meta.env.BASE_URL}`} element={}>
                            
                                       <Route index element={} />
                            
                                       <Route path={`${import.meta.env.BASE_URL}firebase/firebasesignin`} element={} />
                                       <Route path={`${import.meta.env.BASE_URL}firebase/firebasesignup`} element={} />
                                        //<Route path={`${import.meta.env.BASE_URL}firebase/firebasereset`} element={} />
                            
                            
                                       <Route path='*' element={} />
                            
                                       <Route path={`authentication/login`} element={} />
                                       <Route path={`${import.meta.env.BASE_URL}authentication/register`} element={} />
                                       <Route path={`${import.meta.env.BASE_URL}authentication/forgotpassword`} element={} />
                                       <Route path={`${import.meta.env.BASE_URL}authentication/lockscreen`} element={} />
                                       <Route path={`${import.meta.env.BASE_URL}authentication/underconstruction`} element={} />
                                       <Route path={`${import.meta.env.BASE_URL}authentication/errorpages/error400`} element={} />
                                       <Route path={`${import.meta.env.BASE_URL}authentication/errorpages/error401`} element={} />
                                       <Route path={`${import.meta.env.BASE_URL}authentication/errorpages/error403`} element={} />
                                       <Route path={`${import.meta.env.BASE_URL}authentication/errorpages/error404`} element={} />
                                       <Route path={`${import.meta.env.BASE_URL}authentication/errorpages/error500`} element={} />
                                       <Route path={`${import.meta.env.BASE_URL}authentication/errorpages/error503`} element={} />
                                     </Route>
                            
                                      //main route
                            
                                     <Route path={`${import.meta.env.BASE_URL}`} element={}>
                                        {Routedata.map((idx: any) => (
                                         <Route key={idx.id} path={idx.path} element={idx.element} />
                                        ))}
                                     </Route>
                            
                                   </Routes>
                                 </BrowserRouter>
                               </HelmetProvider>
                             </Fragment>
                            );
                            
							
Configure Link in Menu

To Add new link in Sidemenu

Following are the fundamental building blocks to creating a new link.


├── src
    ├──components
        ├──layout-components
            ├──sidebar
                ├──nav.tsx

export const MENUITEMS: any = [

    {
        menutitle: "MAIN",
    },

    { path: `${import.meta.env.BASE_URL}dashboard`, title: "Dashboard", icon: 'fe-home', type: "link", active: false, selected: false, dirchange: false },
	]