Skip to content

Conversation

@azzzy
Copy link

@azzzy azzzy commented Dec 10, 2025

Problem

The Router's CloudFront function uses simple startsWith() matching for paths, causing incorrect route matching when paths share a common prefix.

For example:

  • Route /travel-plan incorrectly matches /travel-plans
  • Route /api incorrectly matches /api-docs

Solution

Updated the path matching logic to check for proper path segment boundaries. A path now only matches if:

  • The URI exactly equals the path, OR
  • The character after the matched prefix is /, OR
  • The route is the root path /

Changes

  • Modified CF_ROUTER_INJECTION in platform/src/components/aws/router.ts (line ~1541)
  • Added unit tests in platform/test/components/router-path-matching.test.ts

Testing

The test file duplicates the path matching logic rather than importing it because the actual implementation lives inside a CloudFront function string literal. This allows testing the logic in isolation without complex string parsing.

Verified with live CloudFront deployment:

  • /travel-plans correctly does NOT match route /travel-plan
  • /travel-plan/abc correctly matches route /travel-plan
  • All existing routes continue to work as expected

Breaking Changes

None. This is a bug fix that corrects unexpected behavior.

Route paths now only match at proper segment boundaries.
Previously /travel-plan incorrectly matched /travel-plans.

Changes:
- Updated path matching logic to check for exact match or trailing slash
- Added unit tests for path matching edge cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant