Jumbo React
Jumbo 6.x
Jumbo 6.x
  • Overview
  • Package Content
  • Installation and Setup
    • Environment Setup
    • Project Setup
  • Structure
    • Folder Structure
  • Layouts
    • Understanding Layouts
    • Pre-built Layouts
    • Create Custom Layout
  • Content Layout
    • Understanding Content Layout
  • Routes
    • Understanding Routes
    • Setup a New Route
    • Route Middleware
    • Create Route Middleware
  • Style Customization
    • Understanding Theme
    • Customize Theme
    • Dark Theme
    • Font Changes
  • How To
    • Apply RTL as default
    • Set RTL direction dynamically
    • Make sidebar menus dynamic
  • Auth Implementation
    • Auth Setting
    • Implement Login Form
Powered by GitBook
On this page
  1. Routes

Create Route Middleware

How to create your own custom route middleware

Creating a route middleware is super easy.

A route middleware is nothing but a react component which accepts "fallbackPath" as a prop. Here are steps to create your custom middleware:

Create route middleware component

In Jumbo, all of the route middleware are located inside the /src/app/routes/middleware/ folder.

So, you can create a component folder inside the above folder. For example:

/src/app/routes/middleware/MyRouteMiddlware

Inside this MyRouteMiddleware component, you can create your component file "index.js" with the following code in it:

import React from 'react';
import {Navigate, Outlet} from "react-router-dom";

const MyRouteMiddleware = ({fallbackPath}) => {
    

    if (<your condition to pass test>) {
        return <Outlet/>;
    }

    return <Navigate to={fallbackPath}/>;
};

export default MyRouteMiddleware;

That is it :)

PreviousRoute MiddlewareNextUnderstanding Theme

Last updated 2 years ago