next.js
dc61d29e - Interception routes match from nested route navigation (#84898)

Commit
193 days ago
Interception routes match from nested route navigation (#84898) ### What? Refactors interception route regex generation to fix nested route navigation and improve maintainability. ### Why? Interception routes failed to trigger when navigating from nested descendant routes. The previous implementation had overly complex, fragile regex patterns spread across multiple functions that were difficult to maintain and didn't handle all navigation scenarios correctly. The root cause was an overly restrictive header matching pattern (`/[^/]+` - single segment only) that prevented matching navigation from deeper nested routes like `/groups/123/settings` → `/groups/123/new`. ### How? **Simplified Architecture:** - Consolidated regex generation logic into `route-regex.ts` where it properly belongs - Removed ~230 lines of complex, duplicated regex building code from `generate-interception-routes-rewrites.ts` - Leveraged existing `getNamedRouteRegex()` with a new `reference` parameter to handle parameter name mapping **Parameter Naming Fix:** - Introduced `nxtI` prefix for parameters adjacent to interception markers (e.g., `(.)[id]` → `nxtIid`) - Maintains `nxtP` prefix for regular parameters - Ensures consistent parameter naming across source, destination, and regex patterns **Regex Pattern Fix:** - Changed header matching from single-segment (`/[^/]+)?` to multi-segment `(/.+)?` pattern - Now correctly matches navigation from any descendant route depth **Test Coverage:** - Added comprehensive e2e tests for nested navigation scenarios - Updated existing tests to reflect new parameter naming convention Fixes #84813 NAR-445
Author
Parents
Loading