Skip to content

feat(matcher): hint at params: {} workaround in discarded params warning#2689

Merged
posva merged 1 commit into
mainfrom
fix/catch-all-redirect-warning-hint
Apr 22, 2026
Merged

feat(matcher): hint at params: {} workaround in discarded params warning#2689
posva merged 1 commit into
mainfrom
fix/catch-all-redirect-warning-hint

Conversation

@posva

@posva posva commented Apr 22, 2026

Copy link
Copy Markdown
Member

Closes #1617. Supersedes #2662 (credits original author via Co-authored-by).

Appends a hint to the dev-only "Discarded invalid param(s)" warning when the params were inherited from the current location and the target matcher has no keys — the classic catch-all → named-redirect case.

Tests: added a matcher-level test for the hint, and a router-level test asserting the params: {} workaround silences the warning entirely.

Summary by CodeRabbit

  • Tests

    • Extended coverage for parameter validation warnings during route matching
    • Added validation tests for inherited parameters in catch-all redirect scenarios
  • Bug Fixes

    • Enhanced warning messages for discarded invalid parameters during route navigation
    • Improved guidance for configuring catch-all routes with named redirects using empty parameter workarounds

…rning

Closes #1617

Co-authored-by: shanliuling <1362913430@qq.com>
@netlify

netlify Bot commented Apr 22, 2026

Copy link
Copy Markdown

Deploy Preview for vue-router canceled.

Name Link
🔨 Latest commit 11a3ae5
🔍 Latest deploy log https://app.netlify.com/projects/vue-router/deploys/69e8c5010fb41b00088856fc

@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Extended warning validation for catch-all routes with named redirects. Added test cases verifying that invalid params trigger appropriate hints when inherited during matching, and refined the warning message to suggest using { name: ..., params: {} } to suppress warnings in this scenario.

Changes

Cohort / File(s) Summary
Test Coverage
packages/router/__tests__/warnings.spec.ts
Extended discard-params test to assert that "catch-all with named redirect" hint is not emitted when params are explicitly provided. Added two new tests: one verifying both "Discarded invalid param(s)" warning and catch-all hint emission when params are inherited; another confirming no warning when using { name: ..., params: {} } workaround.
Warning Message Enhancement
packages/router/src/matcher/index.ts
Modified resolve() function to detect inherited invalid params in catch-all redirect scenarios and append a hint message suggesting the { name: ..., params: {} } workaround to avoid the warning.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A catch-all route with a name redirect call,
No more warnings echoing through the hall!
With hints we provide and tests we compile,
Invalid params now fade with a smile. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a hint about the params: {} workaround to the discarded params warning, which is the core objective of the PR.
Linked Issues check ✅ Passed The PR addresses issue #1617 by implementing a warning hint for catch-all to named-redirect scenarios, helping developers understand the params: {} workaround when inherited params are discarded.
Out of Scope Changes check ✅ Passed All changes are directly scoped to addressing the linked issue: warning message enhancement in matcher and comprehensive test coverage, with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/catch-all-redirect-warning-hint

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new

pkg-pr-new Bot commented Apr 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/vue-router@2689

commit: 11a3ae5

@codecov

codecov Bot commented Apr 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.92%. Comparing base (03e2337) to head (11a3ae5).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2689   +/-   ##
=======================================
  Coverage   85.91%   85.92%           
=======================================
  Files          88       88           
  Lines       10071    10078    +7     
  Branches     2311     2316    +5     
=======================================
+ Hits         8653     8660    +7     
  Misses       1407     1407           
  Partials       11       11           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/router/src/matcher/index.ts`:
- Around line 271-279: The heuristic that sets isInherited is too loose; replace
the current some(...) check with a stricter predicate that returns true only
when every discarded param key came from the previous location and (ideally) its
value matches the previous value. Concretely, update the isInherited computation
(the variable used before the warn call) to use invalidParams.every(name => name
in currentLocation.params && currentLocation.params[name] === /* the value being
discarded */) so that the catch-all redirect hint is only appended when all
discarded params were truly inherited from currentLocation.params (matching keys
and values).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3149cb76-381b-46e6-b2c3-703469611ca7

📥 Commits

Reviewing files that changed from the base of the PR and between 03e2337 and 11a3ae5.

📒 Files selected for processing (2)
  • packages/router/__tests__/warnings.spec.ts
  • packages/router/src/matcher/index.ts

Comment on lines +271 to +279
const isInherited =
!matcher!.keys.length &&
invalidParams.some(name => name in currentLocation.params)
warn(
`Discarded invalid param(s) "${invalidParams.join(
'", "'
)}" when navigating. See https://github.com/vuejs/router/blob/main/packages/router/CHANGELOG.md#414-2022-08-22 for more details.`
)}" when navigating.` +
(isInherited
? ` If you are using a catch-all route with a named redirect, pass an empty \`params\` object: \`redirect: { name: '...', params: {} }\`.`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Tighten the inherited-param heuristic before showing the workaround hint.

some(name => name in currentLocation.params) also matches explicitly supplied invalid params whenever the current route happens to have the same param key, e.g. navigating from /:id to a static named route with { params: { id: 'next' } }. That would show the catch-all redirect hint even though the params were not inherited.

Consider requiring all discarded params to come from the current location and, ideally, matching their values before appending the hint.

Possible narrowing
-          const isInherited =
-            !matcher!.keys.length &&
-            invalidParams.some(name => name in currentLocation.params)
+          const locationParams = location.params || {}
+          const isInherited =
+            !matcher!.keys.length &&
+            invalidParams.every(
+              name =>
+                name in currentLocation.params &&
+                locationParams[name] === currentLocation.params[name]
+            )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/router/src/matcher/index.ts` around lines 271 - 279, The heuristic
that sets isInherited is too loose; replace the current some(...) check with a
stricter predicate that returns true only when every discarded param key came
from the previous location and (ideally) its value matches the previous value.
Concretely, update the isInherited computation (the variable used before the
warn call) to use invalidParams.every(name => name in currentLocation.params &&
currentLocation.params[name] === /* the value being discarded */) so that the
catch-all redirect hint is only appended when all discarded params were truly
inherited from currentLocation.params (matching keys and values).

@posva posva merged commit c2b13c6 into main Apr 22, 2026
11 checks passed
@posva posva deleted the fix/catch-all-redirect-warning-hint branch April 22, 2026 13:20
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.

Warning of invalid param for catch all route with named route redirect

1 participant