Decoupling Params with Props
In the index.js
file, let’s adjust the configuration of the about
route with an additional property called props
.
By setting this property’s value as a function which accepts a route
and returns an object containing an user
field of value based on route.query.user
, the router will automatically understand and map any route.query
parameters into the props
of the view component accordingly:
{ Â Â Â Â path: '/about', Â Â Â Â name: 'about', Â Â Â Â component: () => import('../views/AboutView.vue'), Â Â Â Â Â props: route => ({ user: route.query.user || 'Adam' }) }
In the AboutView.vue
file, we will define a prop type user
as follows:
<script setup> import { defineProps } from 'vue' const props = defineProps({ Â Â Â Â user: String }) </script>
And in the <template>
section,...