Exercise 5.4B: Migrate Layout, Home, and Contact

Purpose: To incorporate the Layout, Nav, and Footer into React, along with the simplest pages (Home and Contact), then break the Nav into smaller components.

Step 1. Copy Nav Data to React Project

Copy your nav data from flaskapp/dat/nav.dat to reactapp/src/assets/nav.json. When you use the .json file extension, import navLinks from './assets/nav.json' in React imports the JSON directly.

Step 2. Create Layout and Nav Components

In the reactapp/src/layouts directory, create:

Use the tips below as needed for JSX translation.

Tips for Converting Jinja Templates to JSX Components

The following tips are general for converting HTML / Jinja content to JSX / React content:

Step 3. Migrate Home and Contact Routes

In reactapp/src/pages, create page components for Home and Contact. Copy the HTML from your flaskapp/templates directory (home.html and contact.html). Translate to JSX where needed. In App.jsx, connect the appropriate routes to <Home /> and <Contact /> inside the <Route> tags.

Step 4. Wrap the Layout

As you finish migrating each route, wrap the finished route in <Route element=<Layout /> >.

Note: If you chose to use FlaskPatch from Exercise 5.1, leave the FlaskPatch routes outside of the Layout until you are ready to replace them with the React content, to avoid a double nav and footer. If you did not use FlaskPatch, this is not a concern.

Step 5. Refactor Nav with HamburgerButton and NavLinks Components

To make your Nav more simple and high-level, break down Nav into components. At a minimum:

Since the id in the collapsible div needs to match the "data-bs-target" and "aria-control" attributes, use props to ensure they match in the HamburgerButton and NavLinks components.

Note on Organizing React Code

Take a moment to reflect on how the above instructions above follow the following organizational principles for React code: