Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigating from router-view throws Missing required param #845

Closed
phillduffy opened this issue Mar 25, 2021 · 21 comments
Closed

Navigating from router-view throws Missing required param #845

phillduffy opened this issue Mar 25, 2021 · 21 comments
Labels
bug Something isn't working has workaround A workaround has been found to deal with the issue

Comments

@phillduffy
Copy link

Version

4.0.5

Reproduction link

https://github.com/phillduffy/route-issue

Steps to reproduce

  • Run the repo
  • Navigate to 'Child with Param'
  • Click 'Back Home'

What is expected?

User should navigate back to the home page

What is actually happening?

Exception is being thrown

runtime-core.esm-bundler.js:38 [Vue warn]: Unhandled error during execution of watcher callback at <RouterLink to= {name: "grandchild"} > at <Child onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< Proxy {…} > > at <RouterView> at <Home onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< Proxy {…} > > at <RouterView> at <App>

and

Uncaught (in promise) Error: Missing required param "id" at Object.stringify (vue-router.esm-bundler.js:994) at Object.resolve (vue-router.esm-bundler.js:1410) at Object.resolve (vue-router.esm-bundler.js:2860) at vue-router.esm-bundler.js:2039 at ComputedRefImpl.reactiveEffect [as effect] (reactivity.esm-bundler.js:42) at ComputedRefImpl.get value [as value] (reactivity.esm-bundler.js:828) at vue-router.esm-bundler.js:2041 at ComputedRefImpl.reactiveEffect [as effect] (reactivity.esm-bundler.js:42) at ComputedRefImpl.get value [as value] (reactivity.esm-bundler.js:828) at vue-router.esm-bundler.js:2064


Updating the grandchild link to the following gets around the issue

<router-link :to="{ name: 'grandchild', params: { id: 1 } }" >Grandchild</router-link >

@posva posva added bug Something isn't working has workaround A workaround has been found to deal with the issue labels Mar 25, 2021
@posva
Copy link
Member

posva commented Mar 25, 2021

Good news is the bug disappears in production because the watchers are only there for devtools

@posva posva closed this as completed in 4108814 Mar 25, 2021
@alijuniorbr
Copy link

For those who need and are interested in fixing this problem before the new release of vue-router v4.0.6 can do the following:

in your project directory:

remove the vue-router:
npm r vue-router

install the current version (already corrected, but not published) of the vue-router:
npm i https://github.com/vuejs/vue-router-next/tarball/master

install dependencies and build vue-router:

cd node_modules\vue-router
npm i
npm run build

that's all! now your project contains these corrections that have already been committed, but are awaiting release v4.0.6

of course, don't use this build in production, because it can contain some bugs that will be prevented from v4.0.6 release

@denyncrawford
Copy link

Hi, @alijuniorbr, having same issue here:

image

I have vue-router@4.0.12 installed and this is my router link (1st one):

image

Fun fact: link bellow works normally

By logging the params from beforeEach (to.params) this is what I get:

image

So it is there actually...

Please can I get some help? Thanks!

@tgel0
Copy link

tgel0 commented Dec 8, 2021

For me, the error was caused by a route guard where I didn't add the required param actually. Maybe someone ends up reading this who made the same mistake as me.

@KaKi87
Copy link

KaKi87 commented Oct 17, 2022

Hello,

I was experiencing the very same issue when using this.$route.params and this.$router.resolve in computed properties, although I can't seem to reproduce it on JSFiddle.

My guess is, values inside params turn into undefined between the time when the navigation starts and the time when the component is unmounted.

Because, checking that the params object wasn't empty is the only small fix I needed to prevent the error from being thrown : https://git.kaki87.net/KaKi87/scraper-instagram-gui/commit/85b0377d5bda2108926fa714b94642317c43c9f2

Thanks

@pwang2
Copy link

pwang2 commented Jan 30, 2023

Can we reopen this? I don't think the has workaround works for the others suffering this especially in a migration project from vue2. :(

@villageseo
Copy link

villageseo commented Feb 20, 2023

Still actual problem in "vue-router": "4.1.6". (in development mode only)

@MatthewAry
Copy link

Still actual problem in "vue-router": "4.1.6". (in development mode only)

I agree. I have been able to reproduce this issue with RouterLink but I have not been able to create a sharable reproduction, and it's not been without trying! I can get this issue to show up in my internal app but when I try to recreate the same conditions in a simplified reproduction I can't get the error to present. My learnings so far:

I worry that I suck at explaining thing which is why I wrote what's below

  • Basically I would expect that you don't need to put all params in a RouteLocationNamedRaw object if they can be inherited by the current route.
  • I don't want to have to pass in params for a router link when that particular router link appears on a route already has the param.
  • The link is on a component in a child route, and the param is already defined on the parent route, so if the RouterLink on the child is for another route on the same parent, then it should inherit the param.

@Oleksii14
Copy link

@MatthewAry that is right. I am also experiencing these issues with Vuetify. The temporary solution is not to use v-btn as router link:

<v-btn :to="route" />

Change to

<v-btn @click="$router.push(route)" />

@MatthewAry
Copy link

Please see my comment on what I have learned so far. vuetifyjs/vuetify#17176 (comment)

@postmodernistx
Copy link

My five cents:

I had the same error, Error: Missing required param "id", when navigating back to the "top level route" from a second level subpage. This was happening in one project, but not in the other.

Example navigation: Home/index page (OK) → Some mid-level page (OK) → Second level page (OK) → Back to index (error)

In the erroneous project, I had "top-level dynamic routes", whereas in the working one, each "top level path" was prefixed with something before entering dynamic routes.

Perhaps not a feasible solution, but at least it got rid of the error for now.

Example, not working:

routes: [
  {
    path: '/',
    name: 'Page0',
    component: () => import('../views/Page0.vue'),
    children: [
      {
        name: 'HomeSubpage',
        path: ':homedynamic',
        component: () => import('../views/HomeSubpage.vue'),
      },
    ],
  },
  {
    path: '/:dynamic', // Issue here 🚨
    name: 'Page1',
    component: () => import('../views/Page1.vue'),
    children: [
      {
        path: ':subpage',
        name: 'Page2',
        component: () => import('../views/Page2.vue'),
      },
    ],
  },

And working version:

routes: [
  {
    path: '/',
    name: 'Page0',
    component: () => import('../views/Page0.vue'),
    children: [
      {
        name: 'HomeSubpage',
        path: ':dynamic',
        component: () => import('../views/HomeSubpage.vue'),
      },
    ],
  },
  {
    path: '/expenses', // Working when not a param ✅
    name: 'Page1',
    component: () => import('../views/Page1.vue'),
    children: [
      {
        path: ':subpage',
        name: 'Page2',
        component: () => import('../views/Page2.vue'),
      },
    ],
  },

I suppose I could make the param optional as well, as so (and have an in-component check instead for its existence):

path: '/:dynamic?',

Looking at the docs, I see no code samples with "top-level dynamic names", so maybe not supported. So implementation of navigation failure guards is probably the best way to go ;)

https://router.vuejs.org/guide/advanced/navigation-failures.html#Global-navigation-failures

And in the original sample code, as the "subroute" is prefixed with a beginning /, it becomes a top-level dynamic route? https://github.com/phillduffy/route-issue/blob/main/src/routes.js#L10

@postmodernistx
Copy link

Hmm, I also just noticed that if I use <keep-alive> inside the <router-view>, it triggers the navigation error. 🤔

So the following fails:

<router-view v-slot="{ Component }">
  <transition name="fade" mode="out-in">
    <keep-alive>
      <component :is="Component" />
    </keep-alive>
  </transition>
</router-view>

And this works:

<router-view v-slot="{ Component }">
  <transition name="fade" mode="out-in">
    <component :is="Component" />
  </transition>
</router-view>

I don't know, seems like it's trying to navigate backwards in history maybe? Just guessing.

@acnowland
Copy link

Hmm, its interesting that it happens so many different ways tbh. I also feel like this is just getting completely ignored though by the router devs due to the labeled workaround, but its clearly still occuring. We are mainly noticing it when we are having users hit the back button. Have tried switching things from being computed properties, tried using postFlush, upgraded the router, but continues to occur. No way to actually make a replication of how we use our app but its a very large app and uses alot of dynamic params that are passed around.

@kenneth4896
Copy link

Still actual problem in "vue-router": "4.1.6". (in development mode only)

@MalindiJohn
Copy link

Still having the same issue in vue-router 4.1.6

vue-router.js?v=f9d707fe:552 Uncaught (in promise) Error: No match for
 {"name":"index","params":{}}
    at createRouterError (vue-router.js?v=f9d707fe:552:19)
    at Object.resolve (vue-router.js?v=f9d707fe:1004:15)
    at Object.resolve (vue-router.js?v=f9d707fe:2160:34)
    at resolveNavLinkRouteName (utils.ts:38:3)
    at Proxy.isNavLinkActive (utils.ts:50:3)
    at Proxy._sfc_render (HorizontalNavLink.vue:33:44)
    at renderComponentRoot (chunk-RMIPITSQ.js?v=f9d707fe:2250:39)
    at ReactiveEffect.componentUpdateFn [as fn] (chunk-RMIPITSQ.js?v=f9d707fe:5516:46)
    at ReactiveEffect.run (chunk-RMIPITSQ.js?v=f9d707fe:1418:23)
    at instance.update (chunk-RMIPITSQ.js?v=f9d707fe:5615:52)

Any workaround here?

@rwam
Copy link

rwam commented Jan 30, 2024

Having the same issue using vue-router@4.2.5. I can solve it making all dynamic params optional but a more stable solution would be preferred.

@dante4rt
Copy link

Having same issue in vue-router 4.0.0.

@Bekzod101001
Copy link

Having same issue in vue-router 4.2.5, when using with vuetify navigation drawer

underscope added a commit to tailor-cms/author that referenced this issue Mar 11, 2024
@bbedyukh
Copy link

bbedyukh commented Mar 19, 2024

Idk if the following code can help you, but try it.

I read adding the optional symbol (?) on declartion path solve this problem.

Example

const HistoryCarPage = () => import('@/pages/HistoryCarPage/HistoryCarPage.vue')
const CarPage = () => import('@/pages/CarPage/CarPage.vue')

export default [
  { name: 'cars', path: '/cars', component: CarPage },
  { name: 'cars.history', path: '/cars/:carId?/history', component: HistoryCarPage }
]

Greetings.

@JhumanJ
Copy link

JhumanJ commented Apr 4, 2024

Same issue in latest version of Nuxt

@1nusah
Copy link

1nusah commented Apr 14, 2024

hi, is there any fix for this? major bug with my nuxt app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has workaround A workaround has been found to deal with the issue
Projects
None yet
Development

No branches or pull requests