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

useRoute().params.param evaluates to undefined on navigation from /:param to / when using nested <router-view /> #1629

Closed
DrJume opened this issue Dec 9, 2022 · 5 comments

Comments

@DrJume
Copy link

DrJume commented Dec 9, 2022

Version

4.1.6

Reproduction link

stackblitz.com

--> Open in New Tab and open Console in DevTools.

Steps to reproduce

  1. Use router with subroutes under a nested RouterView (from 'vue-router')
{
  path: '/routerView/',
  component: RouterView,
  children: [
    {
      path: '',
      component: Home,
    },
    {
      path: ':param',
      component: Param,
    },
  ],
},
  1. Watch useRoute().params.param inside Param.vue

What is expected?

Watching useRoute().params.param does not trigger when going from /routerView/123 to /routerView.

What is actually happening?

useRoute().params.param evaluates to undefined when navigating from /routerView/123 to /routerView.

Additional comments

When a nested <router-view /> (component: RouterView) isn't used, it works as expected.

@DrJume
Copy link
Author

DrJume commented Dec 9, 2022

A workaround is to stop the effect of a computed in an onBeforeRouteLeave hook.

const param = computed(() => route.params.param as string)

onBeforeRouteLeave(() => {
  param.effect.stop()
})

@posva
Copy link
Member

posva commented Dec 10, 2022

Normally, one wouldn't put the RouterView in the component option, it should just be omitted and it will work. Did you find any outdated documentation showing to use RouterView like that?

@DrJume
Copy link
Author

DrJume commented Dec 10, 2022

I know, it used to be necessary, but I just wanted to demonstrate that the issue only happens when using a nested RouterView.
To keep it minimal I used RouterView directly, not using it inside of e.g layout component.

@DrJume
Copy link
Author

DrJume commented Dec 10, 2022

This is a real issue happening in a application, where 2-3 nested layouts are used.

@posva
Copy link
Member

posva commented Dec 10, 2022

Duplicate of vuejs/core#7030

@posva posva marked this as a duplicate of vuejs/core#7030 Dec 10, 2022
@posva posva closed this as not planned Won't fix, can't repro, duplicate, stale Dec 10, 2022
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

No branches or pull requests

2 participants