Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2550 +/- ##
=======================================
Coverage 90.50% 90.50%
=======================================
Files 52 52
Lines 6634 6634
Branches 1380 1380
=======================================
Hits 6004 6004
Misses 619 619
Partials 11 11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
tusharpandey13
previously approved these changes
Mar 11, 2026
Contributor
|
lgtm |
tusharpandey13
previously approved these changes
Mar 19, 2026
… requires overloads
tusharpandey13
approved these changes
Mar 23, 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.
Closes #2440
📋 Changes
Problem
While the need for generic support was identified in PR #2529 the previous implementation did not fully allow for type inference. Specifically, the
returnTocallback was still restricted to the baseAppRouterPageRouteOptstype, and the main wrapper did not correctly "tunnel" the specific Page/Layout props through to the returned component.Fix
I have updated the App Router types to be fully generic. By making
AppRouterPageRoute,WithPageAuthRequiredAppRouterOptions, andWithPageAuthRequiredAppRoutergeneric over<P>, TypeScript can now correctly infer specific route parameters (likeidorslug) from the input component and apply them throughout the helper.Changes
AppRouterPageRoute<P>: Updated the definition to be generic, allowing it to accept narrow types like Next.jsPageProps<T>.WithPageAuthRequiredAppRouterOptions<P>: Added the generic parameter so that thereturnTocallback is now strongly typed based on the specific page being protected.WithPageAuthRequiredAppRouter: Updated the signature to capture the component's props type (P) and propagate it to both the handler and the options.Pworks for developers using Typed Routes.📎 References
Promiseprops.🎯 Testing
returnTo: async ({ params }) => ...now provides full autocomplete for specific dynamic route segments.PageProps<"/route">no longer triggers "Type mismatch" errors when passed to the wrapper.= AppRouterPageRouteOptsas a default type.Manual Test Case
You can verify the fix by checking the type of
paramsinside thereturnTofunction: