Repository navigation
fix(router): match StaticRouter root route on the page root - #21
Merged
Merged
Conversation
851a497 made requestPath() trim slashes off WP::$request, so /portal/ arrives as /portal. isRouteMatched() still built "portal/" for a root route, compiling to ~^/portal//?$~, which needs a slash after the page name. Root routes, and empty paths inside a prefix group, stopped matching and SSR content was lost on the page root. Route paths are now joined by joinPath(), which skips empty segments, so a root route compiles to ~^/portal/?$~ and matches with or without the trailing slash. Fixes #20 Assisted-By: AI
Rector 2.7 with phpstan 2.3 on PHP 8.4+ infers the array type from the getParameters() callers and fails the CI dry-run. The method is private, so the type is BC-safe. Assisted-By: AI
csemazharul
approved these changes
Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #20 (regression from 2.4.0, introduced in 851a497).
Problem
requestPath()trims slashes offWP::$request, so/portal/arrives as/portal.isRouteMatched()still builtportal/for a/route, compiling to~^/portal//?$~, which requires a slash after the page name. Root routes stopped matching and plugins lost their SSR output (title, meta, prerendered content) on the page root, e.g. the Bit Connect portal home. Empty-path routes inside a prefix group (prefix('account')->get('/')) broke the same way.Fix
Route paths are joined by a private
joinPath()helper that skips empty segments, used by bothroutePath()andisRouteMatched(). A root route now compiles to~^/portal/?$~and matches with or without the trailing slash. Rewrite rules are unchanged (RewriteRuleSet::addPath()already trims).Tests
8 new cases in
StaticRoutingTest:main): root via parsedWP::$request, root on a subdirectory install (/blog), root via theREQUEST_URIfallback, empty path inside a prefix group.landing-archive), root does not shadow sibling routes.Full suite: 313 tests pass; lint and compat pass.
CI fix (also red on main)
mainfails thecomposer rectorstep since #19 landed after the rector 2.7 bump (#18). Twochorecommits add the return/param types rector 2.7 + phpstan 2.3 require:InteractsWithHeaders(unreleased, BC-safe) and privateRouteRegister::processParameters(). Merging this PR turnsmaingreen again.🤖 Generated with Claude Code