Skip to main content
πŸ‘€ Interested in the latest enterprise backend features of refine? πŸ‘‰ Join now and get early access!
Version: 4.xx.xx

7. Layout, Menu and Breadcrumb

In Unit 2.4, we created the CRUD pages automatically with Inferencer and wrapped them with a <Layout> component.

This component is provided when you create a new application using create-refine-app to help you get started quickly by providing simple implementations of Menu and Breadcrumb components using refine's hooks, useMenu and useBreadcrumb.

Here is the preview for the Layout, Menu and Breadcrumb components:

localhost:3000

Layout​

When you create a new application with the refine, it creates a default layout under the src/components/layout.tsx file and it looks like below:

src/components/layout.tsx
import { PropsWithChildren } from "react";

import { Menu } from "../menu";
import { Breadcrumb } from "../breadcrumb";

export const Layout: React.FC<PropsWithChildren> = ({ children }) => {
return (
<div className="layout">
<Menu />
<div className="content">
<Breadcrumb />
<div>{children}</div>
</div>
</div>
);
};

It has a Menu and a Breadcrumb component and it renders the children. You can completely customize this component to your needs.

The Menu component is located in the src/components/menu.tsx file and it looks like below:

src/components/menu.tsx
import { useMenu } from "@refinedev/core";
import { NavLink } from "react-router-dom";

export const Menu = () => {
const { menuItems } = useMenu();

return (
<nav className="menu">
<ul>
{menuItems.map((item) => (
<li key={item.key}>
<NavLink to={item.route}>{item.label}</NavLink>
</li>
))}
</ul>
</nav>
);
};

It uses the useMenu hook to get the menu items and renders them as a list. Also, it uses the NavLink component from the react-router-dom package to render the links.

For more information, refer to the useMenu documentation β†’

The Breadcrumb component is located in the src/components/breadcrumb.tsx file and it looks like below:

src/components/breadcrumb.tsx
import { useBreadcrumb } from "@refinedev/core";
import { Link } from "react-router-dom";

export const Breadcrumb = () => {
const { breadcrumbs } = useBreadcrumb();

return (
<ul className="breadcrumb">
{breadcrumbs.map((breadcrumb) => (
<li key={`breadcrumb-${breadcrumb.label}`}>
{breadcrumb.href ? (
<Link to={breadcrumb.href}>{breadcrumb.label}</Link>
) : (
<span>{breadcrumb.label}</span>
)}
</li>
))}
</ul>
);
};

It uses the useBreadcrumb hook to get the breadcrumb items and renders them as a list. Also, it uses the Link component from the react-router-dom package to render the links.

For more information, refer to the useBreadcrumb documentation β†’


Checklist