Routing
The Pizza Chef Frontend uses React Router DOM v7 for client-side routing. This document covers the routing architecture, route configuration, and navigation patterns.Router Configuration
The application uses aBrowserRouter with nested routes defined in App.tsx:
Route Structure
The application uses a nested route architecture with a shared layout.Route Hierarchy
Visual Route Tree
Layout Component
TheLayout component wraps all routes and provides consistent UI structure:
- Header/Navigation: Persistent navigation bar across all pages
- Outlet: React Router’s
<Outlet />component renders child routes - Cart Sidebar: Persistent shopping cart accessible from all pages
Route Definitions
Dashboard (Index Route)
Path:/Component:
Dashboard
Purpose:
- Main landing page
- Displays pizza catalog with filtering and sorting
- Search functionality
- Category filters (Vegetarian, Meat, Seafood, Spicy)
- Price range slider
- Grid of clickable pizza cards
- Connected to
pizzaslice for catalog data - Real-time filtering using Redux state
- Responsive grid layout (1-4 columns based on screen size)
- Click on card navigates to detail page
Pizza Details
Path:/pizza/:idComponent:
PizzaDetailsDynamic Parameter:
id (pizza identifier)
Purpose:
- Detailed view of a single pizza
- Large product image
- Full ingredient list
- Quantity selector
- “Add to Cart” functionality
- Shows discount badge if 3+ items
/pizza/margherita-classic/pizza/pepperoni-deluxe/pizza/seafood-special
Add Pizza
Path:/add-pizzaComponent:
AddPizza
Purpose:
- Form to create custom pizzas
- Uses React Hook Form + Zod validation
- Live preview card
- Adds pizza to catalog on submission
- Pizza name (required, min 3 characters)
- Price (required, min $5.00)
- Category (dropdown: Vegetarian, Meat, Seafood, Spicy)
- Ingredients (multi-select, min 2 items)
- Image URL (optional, with validation)
- Mark as recommended (checkbox)
- Dispatches
addPizzaToCatalogaction - Persists to localStorage
- Navigates back to dashboard
- Shows success toast notification
Analytics
Path:/analyticsComponent:
AdminAnalytics
Purpose:
- Business intelligence dashboard
- Visual charts using Recharts
- Price distribution analysis
- Order popularity metrics
- Price Distribution Chart: Bar chart showing price ranges across catalog
- Order Distribution Chart: Pie chart of most popular pizzas from order history
- Revenue Analytics: Total sales, average order value
- Trending Items: Most frequently ordered pizzas
- Reads from
orderHistoryin Redux state - Aggregates data from completed orders
- Real-time updates as new orders complete
About
Path:/aboutComponent:
About
Purpose:
- Information about the application
- Technology stack details
- Feature highlights
- Developer information
Navigation Patterns
Programmatic Navigation
Navigate using theuseNavigate hook:
Link Components
UseLink or NavLink for declarative navigation:
Navigation with State
Pass state between routes:Route Guards & Protection
While this application doesn’t implement authentication, here’s how you would add protected routes:Dynamic Route Parameters
Accessing Parameters
Multiple Parameters
For routes with multiple dynamic segments:Query Parameters
Handle URL query strings:Scroll Behavior
Scroll to Top on Route Change
Preserve Scroll Position
Error Handling
404 Not Found
Add a catch-all route:Error Boundaries
Handle component errors:Route-Based Code Splitting
Optimize bundle size with lazy loading:- Smaller initial bundle size
- Faster first page load
- Components loaded on demand
- Automatic code splitting by route
Navigation Menu Implementation
Typical navigation menu usingNavLink:
Best Practices
1. Use Index Routes for Defaults
2. Type Route Parameters
3. Use Relative Paths in Nested Routes
4. Prefer Link Over Manual Navigation
5. Use replace for Redirects
Performance Tips
- Lazy load routes: Use
React.lazy()for code splitting - Prefetch routes: Preload likely next routes on hover
- Minimize Layout shifts: Use Suspense fallbacks that match component size
- Cache route data: Store fetched data in Redux to avoid refetching
Next Steps
- State Management - Redux integration with routing
- Data Persistence - Persisting route-related state