The Web Router is the layer that maps incoming HTTP requests to your React/Vite SPA views without ever touching WordPress’s own template hierarchy.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Ahondev/portfolio-v2/llms.txt
Use this file to discover all available pages before exploring further.
WebRoute is a static facade you use inside configuration/routes/web.php; WebRouter is the singleton that stores routes, auto-creates WP pages in development, and dispatches the actual request at wp_loaded priority 5.
WebRoute Facade
WebRoute delegates every call to the WebRouter singleton, giving you a clean static API that reads like a standard web framework router.
WebRoute::get()
Register a GET route pointing to a controller action.
The URI path to match, e.g.
'/' or '/contact'. Leading slash required.Human-readable name used as the WordPress page title when the route is auto-registered in development mode.
A two-element array:
[ControllerClass::class, 'methodName']. The controller must extend WebController.WebRoute::post()
Register a POST route.
The URI path to match.
The controller class name string. Note: the source type hint is
string but the internal implementation accesses it with array index notation — pass a two-element array [ControllerClass::class, 'methodName'] exactly as you would for get().Human-readable route name.
When
true, restricts the route to logged-in users. Defaults to false.WebRoute::CPT()
Bind a custom post type to both an archive URL and individual single-post URLs under a shared base path.
The base URL prefix, e.g.
'/blog'. The router will match /blog (archive) and /blog/{slug} (single) automatically.The
EloquentCPT subclass. The router reads $postType::$model to look up WordPress posts.A controller class that implements both
archive() and single(?EloquentCPT $post) methods.Your CPT controller must implement both
archive(): string and single(?EloquentCPT $post): string methods. The router calls these directly by name — no interface is enforced at compile time, but a missing method causes the request to return false silently.WebRoute::group()
Prepend a shared prefix to an array of existing route paths. Pass the route paths (strings) returned by earlier get() / post() calls.
The path segment to prepend to every listed route.
An array of route path strings that were already registered.
WebRouter (Singleton)
WebRouter is the engine behind the facade. It is instantiated once by WebRouter::init() and stored as a static property.
WebRouter::init()
Creates a new WebRouter instance, loads configuration/routes/web.php to populate the route table, and returns the singleton.
wp_loaded priority 5. You should not call this manually.
WebRouter::instance()
Returns the existing singleton after init() has been called.
addRoute()
Registers a WebRouteDefinition into the route table keyed by its path. In development mode it also calls registerPage() to create the corresponding WordPress page.
registerCPT()
Registers a CPT route configuration. In development mode a WordPress archive page is created automatically.
handleRequest()
The main request dispatcher. Reads $_SERVER['REQUEST_URI'], skips internal WordPress paths (/wp/, /api/, /uploads/, /admin, /client), optionally serves an HTML static-cache file to bots, and then dispatches to the matching controller action.
false when no route matches or when the request targets a WordPress-reserved path. Returns true (and exits) when a route is matched and output has been sent.
Dispatch logic:
Check ignored paths
If the URI starts with
/wp/, /api/, /uploads/, /admin, or /client, return false immediately.Bot detection & static cache
If the visitor is identified as a bot and a pre-rendered HTML file exists in the SSG cache, serve it directly and
exit.Static route match
Look up the full URI in
$routes. If found, instantiate the controller and call its method, echo the output, and exit.getCurrentURI()
Returns the current request path, stripping the trailing slash (root / is left as-is).
pathToSlug() / slugToPath()
Utility methods that convert between URI paths and WordPress page slugs. The root path / maps to the slug 'home'.
routes() / cptRoutes()
Return the internal route tables.
getCacheablePages()
Returns all published WordPress posts that can be statically generated: the built-in page post type plus every post type registered via CPT().
SSGServiceProvider to build the static-site generator’s page list.
WebRouteDefinition Properties
WebRouteDefinition is the value object returned by WebRoute::get() and WebRoute::post().
| Property | Type | Description |
|---|---|---|
$httpMethod | HttpMethod | The HTTP verb enum (GET, POST, …) |
$name | string | Human-readable page name |
$path | string | The URI path (mutable — group() prepends to it) |
$controller | string | Fully-qualified controller class name |
$method | string | Controller method to invoke |
Complete Routes File Example
WebController Base Class
Controllers handling web routes must extendWebController. The key methods are view() and postView():
view() method:
- Collects Vite asset URLs via
Vite::instance()->assets() - Merges view composer data from
ComposerManager - Resolves SEO meta from ACF fields (page meta for static routes, post properties for CPT routes)
- In
?json=1mode, returns a JSON payload for SPA client-side navigation - Otherwise renders
src/SSR/client.phpwhich outputs the full HTML shell