I'm facing an issue with the following code snippet:
<template>
<router-view />
</template>
<script setup lang="ts">
...
const product: Ref<IProduct|undefined>: ref();
...
</script>
The challenge is to pass product
as a prop to the component loaded in the router-view
.
In the past, I could simply use
<router-view :an-prop="product" />
, but after the new version of Vue was released, I started getting a warning:
Extraneous non-props attributes (product) were passed to the component but could not be automatically inherited because the component renders fragment or text root nodes.
I searched through the official documentation but couldn't find any relevant information. After numerous experiments and search engine queries, I discovered that the latest version of router-view
utilizes slots
. This led me to modify the code as follows:
<router-view v-slot="{ Component }">
<component :is="Component" />
</router-view>
Although this change didn't provide much clarity. I am still unsure about what steps to take next. Is there a way to pass props to a component rendered via RouterView in Vue 3?