Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Next.js and React

Vue Router throws away params the target route's path never declared

Your error

[Vue Router warn]: Discarded invalid param(s) "recordIds", "datasources" when navigating.2 more lines it can show

Fix it fast

Most common cause, 1 of 3

Params used to carry page data that the path does not define

Send values that belong in the URL as query and read them back from route.query.

Fix
router.push({ name: 'details', query: { recordIds: recordIds.join(',') } })
// on the target page
const ids = String(route.query.recordIds ?? '').split(',').filter(Boolean)
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Since Vue Router 4.1.4, router.push() with a route name drops every param that the target route's path does not declare, and warns "Discarded invalid param(s) ... when navigating". Sending IDs or objects to another page through params stopped working. Use query, declare a real path param, or pass empty params on a catch-all redirect.

  • Applies to vue-router 5.5.1, vue-router 4.6.5, Vue 3.5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Print the path of the route you push to and compare it with the names in the warning. A name that appears nowhere in the path is cause 1, a near miss is cause 2, and pathMatch (or your catch-all name) is cause 3.

Run this first
console.log(router.getRoutes().map(r => `${String(r.name)} -> ${r.path}`).join('\n'))

Then find the line you see in this list and open its fix:

  1. 1Params used to carry page data that the path does not defineThe discarded names, such as recordIds, exist only in the push() call and nowhere in any route path
  2. 2The param name in push() does not match the name in the pathThe warning names id while the route path says /records/:recordId, and the push may also throw Missing required param
  3. 3A catch-all route redirects by name and hands over its own paramThe discarded name is pathMatch (or whatever the catch-all param is called) and the warning fires on a redirect, not on your own push()

What does the error look like?

  • [Vue Router warn]: Discarded invalid param(s) "recordIds", "datasources" when navigating.
  • [VUE_ROUTER_R0100] Discarded invalid param(s) "recordIds" when navigating. See https://github.com/vuejs/router/commit/e887570 for more details.
  • Missing required param

Cause 1 of 3

Params used to carry page data that the path does not define

You seeThe discarded names, such as recordIds, exist only in the push() call and nowhere in any route path

Check

The 4.1.4 matcher fix removes params that are not part of the target path, so a push like { name: 'details', params: { recordIds } } loses recordIds on the way. The commit note says this breaks apps that relied on such artificial params, calls the pattern advised against for years, and points to query or a real param instead.

Check
grep -rn "params: {" src --include=*.vue --include=*.ts --include=*.js

Fix

Send values that belong in the URL as query and read them back from route.query. Values that cannot be strings, or should not show in the URL, need app state such as a store instead of the router.

Fix
router.push({ name: 'details', query: { recordIds: recordIds.join(',') } })
// on the target page
const ids = String(route.query.recordIds ?? '').split(',').filter(Boolean)

Verify

The address bar shows ?recordIds=... and the target page reads the values with no warning in the console.

Verify
console.log(route.fullPath, route.query)

Confirmed by github.com

Did this fix it?

Cause 2 of 3

The param name in push() does not match the name in the path

You seeThe warning names id while the route path says /records/:recordId, and the push may also throw Missing required param

Check

Only names that the matcher finds among the route's own keys survive. A renamed or misspelled param is discarded like any other, and when the path's required param is then empty, building the URL fails with Missing required param.

Check
console.log(router.resolve({ name: 'record', params: { recordId: '42' } }).href)

Fix

Use exactly the param names written in the route path, or rename the path param to match what callers send.

Fix
// route: { path: '/records/:recordId', name: 'record', component: RecordPage }
router.push({ name: 'record', params: { recordId: record.id } })

Verify

router.resolve returns /records/42 and the page opens with route.params.recordId set.

Verify
console.log(route.params.recordId)

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 3

A catch-all route redirects by name and hands over its own param

You seeThe discarded name is pathMatch (or whatever the catch-all param is called) and the warning fires on a redirect, not on your own push()

Check

When a redirect gives a name and no path, Vue Router copies the params of the route being redirected into the target. Coming from a catch-all such as /:pathMatch(.*)*, that carries pathMatch to a route that does not declare it. Vue Router 5's warning code carries a hint written for this case.

Check
grep -rn -A3 "pathMatch" src/router

Fix

Give the named redirect an empty params object, as the Vue Router 5 message suggests, or redirect with a path instead of a name.

Fix
{ path: '/:pathMatch(.*)*', redirect: { name: 'home', params: {} } }

Verify

Open a URL that no route matches. You land on the home route and the console stays quiet.

Verify
router.push('/no/such/page')

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Treat route params as URL parts only: if a value is not in the path pattern, it goes in query or app state from the start.
  • Generate links with router.resolve in a unit test for each named route, so a renamed path param fails the test before it ships.
  • Give every catch-all redirect an explicit params: {} or a path target when you write it.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.