Vue JS Syntax error: "Unexpected Token, expected ,

Issue

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?

Solution

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.

Answered By – alph╬▒

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published