Skip to main content

Page Detail Component

The PageDetail component is a catch-all route handler that fetches and renders WordPress pages by their slug. It enables content editors to create custom pages in WordPress CMS without requiring code changes.

Location

File: pages/PageDetail.tsx
Route: /:slug (catch-all)

Purpose

This component allows non-technical users to:
  • Create new pages in WordPress admin
  • Publish content without deploying code
  • Maintain consistent branding and layout
  • Add custom landing pages, legal pages, or campaign pages

Route Configuration

Defined in App.tsx:39 as the last route (catch-all):
App.tsx
Route Order Matters: This route MUST be last in the Routes list. If placed earlier, it would intercept all routes including /nosotros, /blog, etc.

Data Flow

1

Extract slug from URL

Uses React Router’s useParams to get the page slug:
Example: URL https://example.com/privacy-policy → slug = "privacy-policy"
2

Fetch WordPress page

Calls fetchWPPageBySlug to retrieve page data:
3

Render page content

Displays the fetched page with title, featured image, and HTML content.

Component Structure

Hero Section

pages/PageDetail.tsx

Content Section

Renders WordPress HTML using Tailwind Typography:
pages/PageDetail.tsx
Security: Uses dangerouslySetInnerHTML to render WordPress HTML. Only use with trusted WordPress sources that sanitize content.

State Management

Loading State

pages/PageDetail.tsx

Error/404 State

pages/PageDetail.tsx

SEO Configuration

pages/PageDetail.tsx

WordPress API Integration

Uses fetchWPPageBySlug from lib/wordpress.ts:82-94:
lib/wordpress.ts

Creating Pages in WordPress

1

Log into WordPress admin

Access your WordPress dashboard at https://your-cms.com/wp-admin
2

Create a new page

Go to Pages → Add New and create your content with the WordPress editor.
3

Set the page slug

In the page settings, set a URL-friendly slug (e.g., privacy-policy).
4

Add featured image (optional)

Set a featured image for the hero section background.
5

Publish

Click Publish. The page is immediately accessible at https://your-site.com/{slug}

Use Cases

  • /privacy-policy - Privacy policy
  • /terms-of-service - Terms and conditions
  • /cookie-policy - Cookie usage policy

Marketing Pages

  • /promo-2024 - Seasonal campaigns
  • /partner-program - Partnership information
  • /case-studies - Customer success stories

Support Pages

  • /shipping-info - Shipping and delivery details
  • /returns - Return policy
  • /faq-extended - Extended FAQ content
Add WordPress pages to footer or navigation:
components/Footer.tsx
  • WPPage - WordPress page data structure

Error Handling

The component handles:
  • Network errors - WordPress API unreachable
  • 404 errors - Page slug doesn’t exist
  • Missing slug - No slug parameter in URL
  • CORS errors - WordPress CORS not configured

Best Practices

Use descriptive slugs: Choose slugs that clearly indicate content (e.g., shipping-policy not page-1)
Set featured images: Hero sections look better with background images. Use high-quality, relevant visuals.
Cache considerations: WordPress REST API responses can be cached. If content doesn’t update immediately, clear cache or check WordPress caching plugins.