🛣️Routing

Page and URL routing

Able Pro routing system is based on react-router and its package react-router-dom, it's also using code splitting for better performance.

How can I add a new page with a menu item?

You can use the below explanation to add/remove menu routes and their menu items.

Configure route

Open ...\src\routes\index.jsx You will find the below example code. In the below code we have shown four different routes. <MainRoutes/> is the main layout routing you see after login.

MainRoutes.jxs
...
...

// ===============|| ROUTING RENDER ||=================== //

export default function ThemeRoutes() {
  return useRoutes([
    {
      path: '/',
      element: <CommonLayout layout="landing" />,
      children: [
        {
          path: '/',
          element: <PagesLanding />
        }
      ]
    },
    LoginRoutes,
    ComponentsRoutes,
    MainRoutes
  ]);
}

Add a New menu/route in the main layout

To add one more menu item in <MainRoutes />, update the following file at the same location ...\src\routes\MainRoutes.js

MainRoutes.jxs
...
...
const SamplePage = Loadable(lazy(() => import('views/sample-page')));
// import new view and save it in constant. for e.g
const NewMenu = Loadable(lazy(() => import('views/new-menu')));

const MainRoutes = {
    path: '/',
    element: (
        <AuthGuard>
            <MainLayout />
        </AuthGuard>
    ),
    children: [
        {
            path: '/sample-page',
            element: <SamplePage />
        },
        {
            path: '/newmenu',
            element: <NewMenu />
        }
    ]
};

export default MainRoutes;

Any route added in <MainLayout> will automatically go through <AuthGuard>

Last updated