Approach 2 Navigation Bar Using Menu Components

In this approach, we have used the menu components including MenuButton, MenuList, MenuItem, and MenuDivider of ChakraUI.

Example: Below example demonstrates the usage of menu component approach to create the navigation.

Javascript




import { useState } from 'react'
import gfgLogo
    from './assets/gfg-new-logo.svg'
import {
    Flex, Box,
    Link, Button,
    Menu,
    MenuButton,
    MenuList,
    MenuItem,
    MenuDivider,
} from "@chakra-ui/react";
 
 
const Nav = () => {
 
    return (
        <Box bg="lightgrey"
            w="100%" h="100%" p={4}>
 
            <Flex mt='3' justifyContent="center">
                <Flex
                    direction="row"
                    alignItems="left"
                    w={{ base: "90%", md: "70%", lg: "50%" }}>
                    <Menu>
                        <MenuButton>
                            <a href="https://www.w3wiki.org/"
                                target="_blank">
                                <img src={gfgLogo}
                                    className="logo react"
                                    alt="gfg logo" />
                            </a>
                        </MenuButton>
                        <MenuList>
                            <MenuItem as='a'
                                href='https://www.w3wiki.org/'>
                                Home
                            </MenuItem>
                            <MenuItem as='a' href='#'>
                                About Us
                            </MenuItem>
                            <MenuItem as='a' href='#'>
                                Contact Us
                            </MenuItem>
                            <MenuDivider />
                            <MenuItem as='a' href=
                                Careers
                            </MenuItem>
                            <MenuItem as='a' href=
                                Our Courses
                            </MenuItem>
                        </MenuList>
                    </Menu>
                </Flex>
            </Flex>
        </Box>
    );
};
export default Nav;


Steps to Run the App:

npm start

Output: Now go to http://localhost:3000 in your browser:



React Chakra UI Navigation

React Chakra UI Navigation Bar is used in every website to make it more user-friendly so that the navigation through the website becomes easy and the user can directly search for the topic of their interest.

Similar Reads

Prerequisites:

NPM and Node React JS HTML, CSS, and JavaScript ReactJS ChakraUI...

Steps to Create React Application And Installing Module:

Step 1: Create a React application using the following command:...

Project Structure:

...

Approach 1: Navigation Bar Using Breadcrumb and LinkBox:

We created the basic box having navigation components like Breadcrumb and LinkBox from the Chakra UI library and placed it for handling a header menu bar with the usual menu items as “Home”, “About”, “Contact” and “Career”. A logo is added with an image icon and a href link is used for adding links to various navigated landing web pages. Access to other links is implemented using HTML href and Chakra UI BreadcrumbLink....

Approach 2: Navigation Bar Using Menu Components:

...