Menu
Coddy logo textTech

Recap: Navigation

Part of the Next.js Essentials section of Coddy's React journey — lesson 38 of 47.

challenge icon

Challenge

Medium

Chapter recap: one small app, both directions of the URL: a nav that reads where it is, and a menu page filtered by the query string.

  1. In components/Nav.jsx, call usePathname() and give each link the className "nav-link active" when its href matches the current path, and plain "nav-link" otherwise. Home is /, Menu is /menu.
  2. In app/menu/page.jsx, read category out of searchParams (remember it's a promise) and show only the matching dishes, or all of them when no category is given.

/menu?category=pizza should show 2 of the 4 dishes, with the Menu link highlighted.

Try it yourself

import './globals.css';
import Nav from '../components/Nav.jsx';

export const metadata = {
    title: 'Coddy Eats',
};

export default function RootLayout({ children }) {
    return (
        <html lang="en">
            <body>
                <Nav />
                {children}
            </body>
        </html>
    );
}

All lessons in Next.js Essentials