Layout

Page layout and navigation

Let's start a basic web application with empty pages.

Create a file ./pages/_app.tsxand start by including these imports:

import useMediaQuery from "@mui/material/useMediaQuery"
import { createTheme, ThemeProvider } from "@mui/material/styles"
import CssBaseline from "@mui/material/CssBaseline"
import { useMemo } from 'react'
import type { AppProps } from "next/app"

It's 2023, so let's enable automatic dark mode, your eyes will thank you tonight. Add the base line and dark theme provider to the App:

export default function App({ Component, pageProps }: AppProps) {
  const prefersDarkMode = useMediaQuery("(prefers-color-scheme: dark)")

  const theme = useMemo(
    () =>
      createTheme({
        palette: {
          mode: prefersDarkMode ? "dark" : "light",
        },
      }),
    [prefersDarkMode]
  )

  return (
    <ThemeProvider theme={theme}>
      <CssBaseline />
        {/* This is where all our providers will "wrap" the page component, for example: */}
        {/* <MyProvider> */}
        <Component {...pageProps} />
        {/* </MyProvider> *}
    </ThemeProvider>
  )
}

Now, create a index.tsx file to the pages folder:

To view your nascent app, run the yarn dev command in the tzombies folder. Navigate to locahost:3000 in your browser. You should see something like this:

To enable navigation, let's add a NavBar. Create a folder ./components and add a ./components/NavBar.tsx. Start the file with the following imports:

There will be two versions of the menu, one when the view is small, as on a smartphone, and one for a desktop view, so let's create a Menu component that we'll reuse in our NavBar:

And the actual NavBar:

Add the NavBar to _app.tsx with the following imports:

And add the NavBar component to the return statement of the App function:

Check that the page opens and the NavBar works as expected. The Connect Wallet button has no effect yet, and navigating leads to 404 since we haven't created them yet.

Let's create them: add three new pages:

  • ./pages/inventory.tsx

  • ./pages/drops.tsx

  • ./pages/market.tsx

And implement empty components in them, like this example:

Last updated