Lesson 5 Lab — Route and Navigate to the Staff Page¶
Wire your Staff page into the shell you just built: give it a route and a nav
link, then extract a StaffCard using props — the same routing + prop-splitting
the guide did for Menu Items. Refer back to the guide for the route tree, Link, and props.
Prerequisite: your API is running on the HTTP profile (
http, nothttps) with CORS enabled and Staff seed data loaded. You're extending theStaffPageyou built in Lesson 4 (fetch + map) and the shell (Layout,AppNav) from this lesson's guide.
Steps¶
Same arc as the guide: route + nav link → extract a Card with props. Your StaffPage
already fetches and maps (Lesson 4); here it gains a route and a StaffCard.
- Add the route. In
main.tsx, add{ path: "staff", element: <StaffPage /> }underLayout'schildren(so it gets the shell), and importStaffPage. - Add the nav link. In the provided
AppNav, add a StaffNav.Item— copy the icon pattern from the Orders/Menu items, using the#peopleicon (bootstrapIconsis already imported): ✅ Checkpoint: click Staff — your staff cards render inside the shell, no full reload. - Extract a
StaffCard(props). Pull the per-member card out ofStaffPageinto aStaffCardthat takes a singlestaffprop, typed with an interface:interface IStaffCardProps { staff: IStaff; } function StaffCard({ staff }: IStaffCardProps) { /* one card: name, username, role badges */ }StaffPagestill fetches and maps; render<StaffCard key={staffMember.id} staff={staffMember} />inside the.map(). The page should look exactly the same — you've just moved one card's markup into a reusable component.
Add Staff button: give
StaffPage's heading an Add Staff<Link to="/staff/create">button. The create page comes in Lesson 7, so the link 404s until then — that's fine.
Verify in the browser¶
Browser checks are covered in the guide — section 7. With npm run dev running:
- Click the Staff nav link — the URL becomes
/staffand the staff cards render inside the shell, no full reload. - Click between Staff, Menu, and Orders — the
Header/AppNavstay put; only the page swaps, and the active nav pill follows the URL. - Use Back — it returns to the previous page.
- Open DevTools → Console — clean. A blank page usually means a missing import or a
pathtypo.
Same routing + props + component-split pattern, a different entity — exactly how you'll route the PRS Users page in the capstone.
Stretch challenges¶
Optional — for when you finish early. Not needed for the capstone. [Reinforce] builds on what you just did; [Reach] goes past the guide and needs some research.
- Active-link styling — [Reinforce] — confirm the current page's nav pill is
highlighted, and click around to watch it follow the URL. The guide's
AppNavusesuseLocation()+defaultActiveKey— trace how the active pill is chosen. - A pass-through prop — [Reinforce] — add a
variantprop toStaffCard(e.g."compact") and use it to toggle a class. Practice defining, typing, passing, and reading a second prop. - Spread the props — [Reinforce] — build a
propsobject and render<StaffCard key={s.id} {...props} />using the spread operator from the guide; confirm it behaves identically to passing each prop by hand. - A 404 route — [Reach] — add a catch-all route (
path: "*") that renders a friendly "Page not found" component, so unknown URLs show your page instead of the generic error. Reference: Route (react-router v6).
Finished these and want more? See stretch-react-challenges.md for bigger challenges that span the whole React pass.