Reactstrap is a popular front-end library that is easy to use React Bootstrap 4 components. This library contains the stateless React components for Bootstrap 4. Breadcrumb Component provides a way to indicate the location of the current page. We can use the following approach in ReactJS to use the ReactJS Reactstrap Breadcrumb Component.
Breadcrumb Props:
- tag: It is used to denote the tag for this component.
- listTag: It is used to denote the list tag like ol, ul, etc.
- className: It is used to denote the class name for the Breadcrumb component.
- listClassname: It is used to denote the class name for list styling.
- cssModule: It is used to denote the CSS module for styling.
- children: It is used to pass the children element to this component.
- aria-label: It is used to denote the aria-label attribute.
BreadcrumbItem Props:
- tag: It is used to denote the tag for this component.
- active: It is used to indicate whether the Item is in active state or not.
- className: It is used to denote the class name for styling.
- cssModule: It is used to denote the CSS module for styling.
Â
Creating React Application And Installing Module:
Step 1: Create a React application using the following command:
npx create-react-app foldername
Step 2: After creating your project folder i.e. foldername, move to it using the following command:
cd foldername
Step 3: After creating the ReactJS application, Install the required module using the following command:
npm install reactstrap bootstrap
Project Structure: It will look like the following.
Project Structure
Example 1: Now write down the following code in the App.js file. Here, we have used the Breadcrumb component with active and href props.
Javascript
import React from 'react'import 'bootstrap/dist/css/bootstrap.min.css'; import { Breadcrumb, BreadcrumbItem } from "reactstrap"Â Â function App() { Â Â Â Â return ( Â Â Â Â Â Â Â Â <div style={{ Â Â Â Â Â Â Â Â Â Â Â Â display: 'block', width: 700, padding: 30 Â Â Â Â Â Â Â Â }}> Â Â Â Â Â Â Â Â Â Â Â Â <h4>ReactJS Reactstrap Breadcrumb Component</h4> Â Â Â Â Â Â Â Â Â Â Â Â <Breadcrumb> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <BreadcrumbItem><a href="#">Dashboard</a></BreadcrumbItem> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <BreadcrumbItem active>Profile</BreadcrumbItem> Â Â Â Â Â Â Â Â Â Â Â Â </Breadcrumb> Â Â Â Â Â Â Â Â Â Â Â Â <Breadcrumb> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <BreadcrumbItem><a href="#">Logout</a></BreadcrumbItem> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <BreadcrumbItem><a href="#">Settings</a></BreadcrumbItem> Â Â Â Â Â Â Â Â Â Â Â Â </Breadcrumb> Â Â Â Â Â Â Â Â </div> Â Â Â Â ); } Â Â export default App; |
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Â
Output: Now open your browser and go to http://localhost:3000/, you will see the following output:
Â
Example 2: Now write down the following code in the App.js file. Here, we have used the Breadcrumb component with disabled, tag, and href props.
App.jsÂ
Javascript
import React from 'react'import 'bootstrap/dist/css/bootstrap.min.css'; import { Breadcrumb, BreadcrumbItem } from "reactstrap"Â Â function App() { Â Â Â Â return ( Â Â Â Â Â Â Â Â <div style={{ Â Â Â Â Â Â Â Â Â Â Â Â display: 'block', width: 700, padding: 30 Â Â Â Â Â Â Â Â }}> Â Â Â Â Â Â Â Â Â Â Â Â <h4>ReactJS Reactstrap Breadcrumb Component</h4> Â Â Â Â Â Â Â Â Â Â Â Â <Breadcrumb listTag="div" tag="nav" > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <BreadcrumbItem disabled>Dashboard</BreadcrumbItem> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <BreadcrumbItem href="#" tag="a" >Profile</BreadcrumbItem> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <BreadcrumbItem href="#" tag="a" >Logout</BreadcrumbItem> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <BreadcrumbItem disabled>Settings</BreadcrumbItem> Â Â Â Â Â Â Â Â Â Â Â Â </Breadcrumb> Â Â Â Â Â Â Â Â </div> Â Â Â Â ); } Â Â export default App; |
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Output: Now open your browser and go to http://localhost:3000/, you will see the following output:
Output
Reference: https://reactstrap.github.io/components/breadcrumbs/
