I want to make search page which after i click its button will be redirect to another page. And this page will be like this
http://localhost:8080/search?q=foo
and my router index.js
looks like this
const routers = [
{
path: '/search',
name: 'Search',
component: SearchPage,
props: route => ( { query: route.query.q } )
}
]
and the question is how do i get the query value in target page SearchPage
, in VueJs 3?
this Answer still confusing me, because not using composition API and not in vuejs 3
First change the router mapping so that
query
maps to thequery
object:In the destination component,
SearchPage
, create aquery
prop which will receive thequery
object from the router:And access it in
setup
via theprops
argument:another setup you can try, send propname by url
{ path: '/search/:propname', name: 'Search', component: SearchPage, props: true },
and on searchpage, on created() you can get recive it
this.$route.params.propname