]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
docs: add example about passing props
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 23 Oct 2023 18:52:04 +0000 (20:52 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 23 Oct 2023 20:25:48 +0000 (22:25 +0200)
Co-authored-by: Björn Harrtell <bjornharrtell@users.noreply.github.com>
packages/docs/guide/essentials/passing-props.md

index 56631771aa29edaed6ae43d29e0fe815f75f5ff8..c1b2d21c15f2959401489593718dc39370aa6957 100644 (file)
@@ -78,3 +78,20 @@ const routes = [
 The URL `/search?q=vue` would pass `{query: 'vue'}` as props to the `SearchUser` component.
 
 Try to keep the `props` function stateless, as it's only evaluated on route changes. Use a wrapper component if you need state to define the props, that way Vue can react to state changes.
+
+## Via RouterView
+
+You can also pass any props directly via `<RouterView>`:
+
+```vue-html
+<RouterView v-slot="{ Component }">
+  <component
+    :is="Component"
+    view-prop="value"
+   />
+</RouterView
+```
+
+::: warning
+In this case, **all view components** will receive `view-prop`. This is usually not a good idea as  it means that all of the view components have declared a `view-prop` prop, which is not necessarily true. If possible, use any of the options above.
+:::