Mantis MUI React
v3.5.0
v3.5.0
  • Documentation
  • Pre-requisites
  • Quick Start
  • Package
  • Folder Structure
  • State Management
  • Internationalization
  • Authentication
    • Switch to Auth0
    • Switch to Firebase
    • Switch to AWS Cognito
    • Switch to Supabase
  • Axios API Calls
  • Routing
  • Project Configuration
  • Color Presets
  • Theme/Style Configuration
  • How to
    • Login as First Page
    • Dashboard as First Page
    • Render Menu from the backend
    • Remove menu render from Backend
    • Remove Authentication
      • Vite
      • NextJS
  • Figma
  • Integration
    • Seed
    • To Existing Project
    • Comparison
  • Components
    • Avatar
    • BreadCrumb
    • Button
    • Dot
    • Main Card
    • Progress
    • SnackBar
    • Tooltip
    • Transitions
  • Dependencies
  • Roadmap
  • Support
  • Changelog
  • Mantis Eco System
  • FAQ
Powered by GitBook
On this page
  • Configure route
  • Add a New menu/route in the main layout

Routing

Page and URL routing

PreviousAxios API CallsNextProject Configuration

The Mantis routing system is based on and its package it's also using code splitting for better performance.

This documentation page elaborates on routing using react-router. Given that Next.js employs the 'APP' directory, no supplementary documentation is required in this regard. You can refer to Next.js' 'APP' directory routing here: .

For further insights into Mantis Next.js' directory structure, please refer to: .

Configure route

Open src\routes\index.jsx and 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.

routes/index.tsx
import { lazy } from 'react';
import { createBrowserRouter } from 'react-router-dom';

// project import
...
...

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

const router = createBrowserRouter(
  [
    {
      path: '/',
      element: <SimpleLayout layout={SimpleLayoutType.LANDING} />,
      children: [
        {
          index: true,
          element: <PagesLanding />
        }
      ]
    },
    LoginRoutes,
    ComponentsRoutes,
    MainRoutes
  ],
  { basename: APP_BASENAME }
);

export default router;
routes/index.jsx
import { lazy } from 'react';
import { createBrowserRouter } from 'react-router-dom';

// project import
...
...

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

const router = createBrowserRouter(
  [
    {
      path: '/',
      element: <SimpleLayout layout={SimpleLayoutType.LANDING} />,
      children: [
        {
          index: true,
          element: <PagesLanding />
        }
      ]
    },
    LoginRoutes,
    ComponentsRoutes,
    MainRoutes
  ],
  { basename: process.env.REACT_APP_BASE_NAME }
);

export default router;

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.

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.jsx

routes/MainRoutes.tsx
...
import DashboardLayout from 'layout/Dashboard';
...

// render - dashboard
const DashboardDefault = Loadable(lazy(() => import('pages/dashboard/default')));
// import new view and save it in constant. for e.g
const NewMenu = Loadable(lazy(() => import('views/new-menu')));
...

const MainRoutes = {
  path: '/',
  children: [
    {
      path: '/',
      element: <DashboardLayout />,
      children: [
        {
          path: 'dashboard',
          children: [
            {
              path: 'default',
              element: <DashboardDefault />
            },
            {
              path: 'new-menu-route-name',
              element: <NewMenu />
            ...
        }
      ]
      ...
    }
    ...
  ]
};

export default MainRoutes;
routes/MainRoutes.jsx
...
import DashboardLayout from 'layout/Dashboard';
...

// render - dashboard
const DashboardDefault = Loadable(lazy(() => import('pages/dashboard/default')));
// import new view and save it in constant. for e.g
const NewMenu = Loadable(lazy(() => import('views/new-menu')));
...

const MainRoutes = {
  path: '/',
  children: [
    {
      path: '/',
      element: <DashboardLayout />,
      children: [
        {
          path: 'dashboard',
          children: [
            {
              path: 'default',
              element: <DashboardDefault />
            },
            {
              path: 'new-menu-route-name',
              element: <NewMenu />
            ...
        }
      ]
      ...
    }
    ...
  ]
};

export default MainRoutes;

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

Further, the same menu needed to be added in respective JSON as well here: src/menu-items/index

    {
      id: 'newmenu',
      title: <FormattedMessage id="newmenu" />,
      type: 'item',
      icon: BuildOutlined,
      url: '/newmenu',
      breadcrumbs: false
    },
    ....
    ...
react-router
react-router-dom,
Next.js Documentation
Next.js Folder Structure