I am using Vue3 with vue-router 4.0.5 and I am experiencing an issue where useRoute() appears to retieve the route correctly but the query of the route is undefined, even though a query exists.
For the path /search?q=vue is it expected that searchQuery equals vue but it returns undefined.
In the template, {{ $route.query.q }} correctly returns the query value.
import { useRoute } from "vue-router"
export default {
name: "Search",
setup() {
const route = useRoute()
const searchQuery = route.query.q
console.log(route)
console.log(searchQuery)
return {
searchQuery
}
}
}
<template>
<div>{{ $route.query.q }}</div>
</template>
When logging to the console, the route object is logged correctly and contains the route's query object but searchQuery is undefined.
I am wondering why searchQuery is returning as undefined in this example.