Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. /*
  2. * to.matched is array for all the route it matches, use m.meta to get flags
  3. * remember to use next() at the end !
  4. * next({name: 'new-route'}) to redirect
  5. */
  6.  
  7. router.beforeEach(async (to, from, next) => {
  8. if (to.matched.some(m => m.meta.needProject)) {
  9. const result = await apolloClient.query({
  10. query: PROJECT_CURRENT,
  11. fetchPolicy: 'network-only'
  12. })
  13. if (!result.data.projectCurrent) {
  14. next({ name: 'project-select' })
  15. return
  16. } else {
  17. await apolloClient.mutate({
  18. mutation: CURRENT_PROJECT_ID_SET,
  19. variables: {
  20. projectId: result.data.projectCurrent.id
  21. }
  22. })
  23. }
  24. }
  25. next()
  26. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement