Pages & Routing Architecture Overview
What Are Pages?
Pages in StockEase are route-connected components that represent distinct sections of the application. Each page is responsible for its own data fetching, state management, and layout.
Key Principles
- Route-Based Organization: Each route has a corresponding page component
- Layout Wrapper: Consistent header, sidebar, and footer across pages
- Authentication Gating: Pages check user authentication and roles
- Lazy Loading: Pages are code-split for faster initial load
- Self-Contained: Each page manages its own state and effects
Routing Architecture
graph TB
App["App.tsx
(Router Setup)"] subgraph "Public Routes" Home["/ β HomePage
(Public)"] Login["/login β LoginPage
(Public)"] end subgraph "Protected Routes" User["/user β UserDashboard
(Authenticated)"] Search["/search-product β SearchProductPage
(Authenticated)"] List["/list-stock β ListStockPage
(Authenticated)"] end subgraph "Admin-Only Routes" Admin["/admin β AdminDashboard
(Admin)"] Add["/add-product β AddProductPage
(Admin)"] Delete["/delete-product β DeleteProductPage
(Admin)"] Edit["/product/:id/edit β ChangeProductDetailsPage
(Admin)"] end App -->|"Route matching"| Home App -->|"Route matching"| Login App -->|"Route matching"| User App -->|"Route matching"| Search App -->|"Route matching"| List App -->|"Route matching"| Admin App -->|"Route matching"| Add App -->|"Route matching"| Delete App -->|"Route matching"| Edit
(Router Setup)"] subgraph "Public Routes" Home["/ β HomePage
(Public)"] Login["/login β LoginPage
(Public)"] end subgraph "Protected Routes" User["/user β UserDashboard
(Authenticated)"] Search["/search-product β SearchProductPage
(Authenticated)"] List["/list-stock β ListStockPage
(Authenticated)"] end subgraph "Admin-Only Routes" Admin["/admin β AdminDashboard
(Admin)"] Add["/add-product β AddProductPage
(Admin)"] Delete["/delete-product β DeleteProductPage
(Admin)"] Edit["/product/:id/edit β ChangeProductDetailsPage
(Admin)"] end App -->|"Route matching"| Home App -->|"Route matching"| Login App -->|"Route matching"| User App -->|"Route matching"| Search App -->|"Route matching"| List App -->|"Route matching"| Admin App -->|"Route matching"| Add App -->|"Route matching"| Delete App -->|"Route matching"| Edit
Route Configuration in App.tsx
<Routes>
{/* Public */}
<Route path="/" element={<HomePage />} />
<Route path="/login" element={<LoginPage />} />
{/* Protected - All Authenticated Users */}
<Route path="/user" element={<UserDashboard />} />
<Route path="/search-product" element={<SearchProductPage />} />
<Route path="/list-stock" element={<ListStockPage />} />
{/* Admin-Only */}
<Route path="/admin" element={<AdminDashboard />} />
<Route path="/add-product" element={<AddProductPage />} />
<Route path="/delete-product" element={<DeleteProductPage />} />
<Route path="/product/:productId/edit" element={<ChangeProductDetailsPage />} />
</Routes>Page Summary Table
| Route | Page Component | Access | Purpose |
|---|---|---|---|
/ |
HomePage | Public | Landing page & introduction |
/login |
LoginPage | Public | User authentication |
/user |
UserDashboard | Authenticated | User inventory view |
/admin |
AdminDashboard | Admin Only | Admin control panel |
/add-product |
AddProductPage | Admin Only | Create new product |
/delete-product |
DeleteProductPage | Admin Only | Delete product |
/product/:id/edit |
ChangeProductDetailsPage | Admin Only | Edit product details |
/search-product |
SearchProductPage | Authenticated | Search & filter products |
/list-stock |
ListStockPage | Authenticated | Complete inventory list |
Page Categories
Public Pages (No Auth Required)
- HomePage: Entry point, features, login link
- LoginPage: Authentication form
Protected Pages (Login Required)
- UserDashboard: User's own inventory
- SearchProductPage: Search across products
- ListStockPage: Full inventory view
Admin Pages (Admin Role Required)
- AdminDashboard: Admin controls
- AddProductPage: Create products
- DeleteProductPage: Delete products
- ChangeProductDetailsPage: Edit products
Navigation Flow
User visits app
ββ Not logged in
β ββ Lands on HomePage
β ββ Can navigate to LoginPage
β
ββ After login (User role)
β ββ Redirected to UserDashboard
β ββ Can access SearchProductPage
β ββ Can access ListStockPage
β
ββ After login (Admin role)
ββ Redirected to AdminDashboard
ββ Can access all user pages
ββ Can access admin pages (Add, Edit, Delete)
Typical Page Structure
Every page follows a consistent pattern:
const PageName: React.FC = () => {
// 1. Authentication check
// 2. State initialization
// 3. Data fetching
// 4. Event handlers
// 5. Conditional rendering (loading, error)
// 6. Layout rendering
};See Page Lifecycle for detailed implementation patterns.
Layout Template
All pages share a consistent layout structure:
βββββββββββββββββββββββββββββββββββ
β Header β
ββββββββββββββ¬βββββββββββββββββββββ€
β β β
β Sidebar β Page Content β
β β β
ββββββββββββββ΄βββββββββββββββββββββ€
β Footer β
βββββββββββββββββββββββββββββββββββ
Components like Header, Sidebar, and Footer are shared across all pages for consistency.
Documentation Structure
This documentation is organized into focused topics:
Overview (this file)
- Routing architecture, route configuration, page summary
-
- Detailed documentation of each page (HomePage, LoginPage, UserDashboard, etc.)
-
- Page component structure, lifecycle hooks, typical patterns
-
- Route protection, role-based access, authentication patterns
-
- Lazy loading, memoization, code splitting, optimization techniques
-
- Testing strategies, test structure, testing patterns
Quick Reference
Access a Protected Page (Admin Only)
<Route
path="/admin"
element={<ProtectedRoute component={AdminDashboard} requiredRole="admin" />}
/>Lazy Load a Page
const AdminDashboard = lazy(() => import('./pages/AdminDashboard'));
<Suspense fallback={<SkeletonLoader />}>
<AdminDashboard />
</Suspense>Check Authentication in Component
const { user, isAuthenticated } = useSelector(state => state.auth);
if (!isAuthenticated) {
return <Navigate to="/login" />;
}Common Tasks
Add a New Page
- Create page component in
src/pages/ - Add route in
App.tsx - Add to navigation (Sidebar, Header)
- Implement authentication check if protected
- Create tests in
src/__tests__/
Protect a Route
<Route
path="/admin"
element={
<ProtectedRoute
component={AdminDashboard}
requiredRole="admin"
/>
}
/>Add Authentication Check in Page
const AdminDashboard: React.FC = () => {
const { user, isAuthenticated } = useSelector(state => state.auth);
if (!isAuthenticated || user?.role !== 'admin') {
return <Navigate to="/login" />;
}
// Page content...
};Related Documentation
- Component Architecture - Detailed page components
- Page Lifecycle - Component structure and patterns
- Authentication - Route protection and access control
- Performance - Optimization and lazy loading
- Testing - Testing strategies
- Main Architecture - Overall app architecture
Last Updated: November 2025
Total Pages: 9 main page components
Protected Routes: 6
Public Routes: 2