Skip to main content

Routing Overview

The VENCOL Front Template uses React Router v6 for client-side routing, providing a seamless single-page application experience.

Router Configuration

Main Router Setup

The application uses BrowserRouter as the main router component in App.tsx:
App.tsx
The catch-all route /:slug must be defined last to prevent it from intercepting other routes. This route handles dynamic WordPress pages.

Route Definitions

Static Routes

Static routes map directly to specific page components:

Dynamic Routes

Dynamic routes use URL parameters to load specific content:

Solution Details

Usage:
  • /soluciones/refrigeracion-comercial
  • /soluciones/sistemas-hvac
Accessing the parameter:
SolutionDetail.tsx

Blog Post Details

Usage:
  • /blog/post-title-here

WordPress Pages (Catch-all)

This route fetches pages from WordPress CMS by slug:
PageDetail.tsx
The Navbar component uses NavLink for active route highlighting:
Navbar.tsx
NavLink automatically receives an isActive boolean in its className function, enabling active state styling.

Solutions Dropdown

The navbar includes a dynamic dropdown for solutions:
Navbar.tsx

Programmatic Navigation

Use the Link component for navigation:

Scroll Behavior

Scroll to Top on Route Change

The application implements automatic scroll-to-top on navigation:
App.tsx
This component is placed inside the Router to access routing context:

Mobile Navigation

Mobile Menu State

The navbar manages mobile menu state with automatic closing on route change:
Navbar.tsx

Mobile Dropdown

The mobile menu includes an expandable solutions section:
Navbar.tsx

Loading States

Dynamic pages implement loading states during data fetching:
PageDetail.tsx

404 Handling

WordPress Page Not Found

The PageDetail component handles missing pages:
PageDetail.tsx
Extract route parameters using useParams hook:
Always provide TypeScript types for parameters.
Place catch-all routes last in the Routes configuration to prevent them from intercepting more specific routes.
Use NavLink instead of Link when you need to style the active route:

Architecture

Learn about the overall application structure

WordPress Integration

Understand how dynamic pages are loaded from WordPress