Open In App

React MUI Breadcrumbs API

Last Updated : 27 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

React MUI is a UI library providing predefined robust and customizable components for React for easier web development. The MUI design is based on top of Material Design by Google. Material-UI is a user interface library that provides predefined and customizable React components for faster and easy web development, these Material-UI components are based on top of Material Design by Google.  

In this article, we are going to discuss the React MUI BreadcrumbsAPI. Breadcrumbs provide a way for users to identify the path to the current resource in an application. There are different ways to design Breadcrumb. 

Import Breadcrumbs API:

import Breadcrumbs from '@mui/material/Breadcrumbs'

 

Props list:

  • children: It is used to denote the content.
  • classes: It is to override or extend the styles applied to the component.
  • maxItems: It is used to denote a maximum number of breadcrumbs to display.
  • expandText: It is the default label for the expand button.
  • itemsAfterCollapse: It is used to denote the number of breadcrumbs to display after the ellipsis.
  • itemsBeforeCollapse: It is used to denote the number of breadcrumbs to display before the ellipsis.
  • separator: It is used to denote a specific symbol for the separator.
  • sx: It is used to add custom CSS styles to the divider.

CSS Rules:

  • root (MuiDivider-root):  It is the style applied to the root element.
  • li (MuiBreadcrumbs-li): It is the style applied to the li element.
  • ol (MuiBreadcrumbs-ol): It is the style applied to the ol element.
  • separator (MuiBreadcrumbs-separator): It applies styles to the separator.

Approach: Let us create a React project and install React MUI module. Then we will create a UI that will showcase React MUI Breadcrumbs API.

Creating React Project:

Step 1: To create a react app, you need to install react modules through npx command. “npx” is used instead of “npm” because you will be needing this command in your app’s lifecycle only once.

npx create-react-app project_name

Step 2: After creating your react project, move into the folder to perform different operations.

cd project_name

Step 3: After creating the ReactJS application, Install the required module using the following command:

npm install @mui/material @emotion/react @emotion/styled

Project Structure: After running the commands mentioned in the above steps, if you open the project in an editor you can see a similar project structure as shown below. The new component user makes or the code changes, we will be performing will be done in the source folder.

Project Structure

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Example 1: We are creating a UI that shows React MUI Breadcrumbs API.

<

App.js




import * as React from 'react';
import Breadcrumbs from '@mui/material/Breadcrumbs';
import Typography from '@mui/material/Typography';
import Link from '@mui/material/Link';
  
export default function Demo() {
    return (
        <div style={{ margin: 100 }}>
            <h1 style={{ color: 'green' }}>GeeksforGeeks</h1>
            <h3><u>React MUI Breadcrumbs API</u></h3>
            <br />
            <Breadcrumbs maxItems={2} >
                <Link color="primary" href="#">
                    GeeksforGeeks</Link>
                <Link color="primary" href="#">
                    Articles</Link>
                <Link color="primary" href="#">
                    Material UI</Link>
                <Link color="primary" href="#">
                    Component API</Link>
                <Typography>Breadcrumbs API</Typography>
            </Breadcrumbs>
        </div>
    );
}


Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

 

Example 2: We are creating a UI that shows React MUI Breadcrumbs API.

App.js




import * as React from 'react';
import BoltIcon from '@mui/icons-material/Bolt';
import Breadcrumbs from '@mui/material/Breadcrumbs';
import Typography from '@mui/material/Typography';
import Link from '@mui/material/Link';
  
export default function Demo() {
    const breadcrumbs = [
        <Link underline="hover" key="1" href="/" >
            Geeks for Geeks
        </Link>,
        <Link underline="hover" key="2" href="#">
            Articles
        </Link>,
        <Typography key="3" >
            Breadcrumb API
        </Typography>,
    ];
    return (
        <div style={{ margin: 100 }}>
            <h1 style={{ color: 'green' }}>GeeksforGeeks</h1>
            <h3><u>React MUI Breadcrumbs API</u></h3>
            <br />
            <Breadcrumbs separator="~~" aria-label="breadcrumb">
                {breadcrumbs}
            </Breadcrumbs><br />
            <Breadcrumbs separator="--" aria-label="breadcrumb">
                {breadcrumbs}</Breadcrumbs>
            <br />
            <Breadcrumbs separator={<BoltIcon />} a
                ria-label="breadcrumb">
                {breadcrumbs}
           </Breadcrumbs>
        </div>
    );
}


Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

 

Reference: https://mui.com/material-ui/api/breadcrumbs/



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads