I've built a search page which sends a request to the wordpress json api. The asyncData method gets it params by submitting a form in a header component. On submit I call the this.$router.push({ name: 'suche', params: {search: this.searchInput}}). On localhost with npm run dev everything works like it should. But when I deploy the route.params.search is undefined in asyncData. I tested to display $route.params.search and it works on both local and production mode (target: static).
asyncData in suche.vue:
async asyncData({route, $axios }) {
try {
// console.log(params.search);
// const anfrage = params.search;
const query = route.params.search
const search = await $axios.$get(`https://wp-api.com/wp-json/wp/v2/multiple-post-type?search=${query}&type[]=post&type[]=project&per_page=20&_embed`)
return { search }
} catch (error) {
if (error.response) {
// Request made and server responded
console.log(error.response.data)
console.log(error.response.status)
console.log(error.response.headers)
} else if (error.request) {
// The request was made but no response was received
console.log(error.request)
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message)
}
}
}
I also tested the router push with path and query.