How to update query on route change using Vue and Urql

104 Views Asked by At

I'm trying to find a way to update my query when the route changes (same component). The query is being selected using route meta data. Between Vue router's navigation guards, hooks, watching for changes, etc, and Urqls "useQuery," I can't figure out how to structure it to give me new data when the route changes. I just want it to recognize that "myQuery" has a new value, and to apply that to the query and rerun it.

const route = useRoute();
const myQuery = route.meta.query;

const posts = await useQuery({
  query: gql`
    query posts {
      ${myQuery} {
        title
        description
        interests {
          title
        }
        createdAt
        image_url
        userId {
          username
        }
      }
    }
  `,
  pause: false
});
const data = posts.data;
0

There are 0 best solutions below