Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Vue appollo and Vue router, How to setup navigation guard #1544

Unanswered
CMarzin asked this question in Q&A
Discussion options

Hello, I have been stuck for a day about this issue and wanted the help of the community.

I use a vuejs ( v3.3.9 )SPA with Vite ( v5.0.12 ) and

  • apollo/client v3.9.8
  • vue/apollo-composable v4.0.2
  • vue router v4.2.5

My goal is to execute a graphql query inside the global guard beforeEach to fetch some data before returning the next() function.

The problem is, I want to use async await in order to "block" the hook beforeEach but the query return the first time an object with { loading: true, partial: true }, so in the beforeEach I need to call two times apolloClient in order to have the data.

I didn't find any clear documentation about this in the repository, if someone can help I will update the documentation with the response.

Thank you for your times.

Edit :
I created a repository with an example of how you can use make a query inside the the global guard of vue router :

https://github.com/CMarzin/vue-apollo-with-vue-router

Edit 2 :
My problem was my implementation of Keycloak, the token was undefined in my router so the request failed silently without any explanation

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /