question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to pass props to an component rendering via RouterView?

See original GitHub issue

Version

4.0.14

Reproduction link

codepen.io

Steps to reproduce

Copy this little code and put it in any Vue3 component.

What is expected?

Prop is passing to children component.

What is actually happening?

Extraneous non-props attributes (product) were passed to component but could not be automatically inherited because component renders fragment or text root nodes.


I have code like:


<template>
 <router-view :an-prop="product" />
</template>
<script setup lang="ts">

...

const product: Ref<IProduct|undefined>: ref();

...

</script>

I need to pass product as a prop to the component which loads in router-view.

Some time ago it was possible just like <router-view :an-prop="product" />, but since new version of Vue was released I’ve got warning:

Extraneous non-props attributes (product) were passed to component but could not be automatically inherited because component renders fragment or text root nodes.

Maybe I’m blind, but I honestly didn’t find anything about it in the official documentation, only trivial examples of using <router-view> and billions of trivial examples of using vue-router programmatically. After hours of experiments and studies search engines’ results I found out that now router-view uses slots and end up with such code:

<router-view v-slot="{ Component }">
 <component :is="Component" />
</router-view>

Which gave me not much, actually. Anyway I don’t understand what to do next. Is there any way to pass props to an component rendering via RouterView nowadays in vue3?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pei-hancommented, Nov 9, 2022

the document of vue-router is sucked. i can not find anything about component element at all.

0reactions
MohammadArefHaidarycommented, Apr 20, 2022

in

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing props to Vue.js components instantiated by Vue-router
Note that this only works if your prop function is scoped so it can see the data you want to pass. The route...
Read more >
Passing Props to Route Components | Vue Router
You can create a function that returns props. This allows you to cast parameters into other types, combine static values with route-based values,...
Read more >
How to Pass Props to a Component Rendered by React Router
In this up-to-date guide, you'll learn everything you need to know about passing props to a component rendered by React Router.
Read more >
Pass props to a component rendered by React Router v5
Pass props to a component rendered by React Router v5---If you enjoyed this video, you'll love our React Router v5 ...
Read more >
Vuejs, how to pass props to a Component rendered by Router?
You may want to forward the props via router-view (which here passes text to the rendered component Text ) <router-view :text="text"></router-view>.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found