Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * to.matched is array for all the route it matches, use m.meta to get flags
- * remember to use next() at the end !
- * next({name: 'new-route'}) to redirect
- */
- router.beforeEach(async (to, from, next) => {
- if (to.matched.some(m => m.meta.needProject)) {
- const result = await apolloClient.query({
- query: PROJECT_CURRENT,
- fetchPolicy: 'network-only'
- })
- if (!result.data.projectCurrent) {
- next({ name: 'project-select' })
- return
- } else {
- await apolloClient.mutate({
- mutation: CURRENT_PROJECT_ID_SET,
- variables: {
- projectId: result.data.projectCurrent.id
- }
- })
- }
- }
- next()
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement