1

I am working on a Django aplication that has VueJS in it. I am new to Django and even newer to VueJS.

I am getting this error when I try to run my code:

ERROR Failed to compile with 1 errors
2:11:51 PM

error in ./src/router/index.js

Syntax Error: Unexpected token, expected , (51:0)

49 | } 50 |

51 | }) | ^ 52 | 53 | export default router 54 |

@ ./src/main.js 5:0-30 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js

here is my router/index.js file contents:

import Vue from 'vue'
import Router from 'vue-router'
import Chat from '@/components/Chat'
import UserAuth from '@/components/UserAuth'

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/chats',
      name: 'Chat',
      component: Chat
    },

    {
      path: '/auth',
      name: 'UserAuth',
      component: UserAuth
    }
  ]
})

router.beforeEach((to, from, next) => {
  if (sessionStorage.getItem('authToken') !== null || to.path === '/auth') {
    next()
    }

  else {
    next('/auth')
    }

  }

})

export default router

What is the reason for the syntax error and how do I correct it?

1
  • 1
    Fix the indentation to be more consistent and I imagine the problem will be self-evident. The call to router.beforeEach() seems structurally incorrect. Commented May 9, 2022 at 18:36

1 Answer 1

1

Check the extra bracket you have in:

router.beforeEach((to, from, next) => {
  if (sessionStorage.getItem('authToken') !== null || to.path === '/auth') {
    next()
    }

  else {
    next('/auth')
    }
  }   <-----------
})

Please remove it, one tip use code editors, most of them will indicate this silly mistakes that you may not realize.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.