nuxt: scrollBehavior - Syntax Error: Unexpected token

"nuxt": "^0.10.7" nuxt.config.js:

router: {
    scrollBehavior: function (to, from, savedPosition) {
      return { x: 0, y: 0 }
    }
  },

gives me:

ERROR  Failed to compile with 1 errors                                                 18:07:50

 error  in ./.nuxt/router.js

Syntax Error: Unexpected token, expected ( (23:32)

  21 |
  22 |
> 23 | const scrollBehavior = function function(to, from, savedPosition) {
     |                                 ^
  24 |       return { x: 0, y: 0 };
  25 |     }
  26 |

Thanks for help,

<div align="right">This question is available on Nuxt.js community (#c618)</div>

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (5 by maintainers)

Most upvoted comments

@dan-gamble @awronski @azorvk There is a solution as below:

scrollBehavior: function _scrollBehavior (to, from, savedPosition) {

And it’s a general bug when define a function property for nuxt.config.js object such as transition.beforeEnter, the function name _scrollBehavior should be whichever except the same name of the object key scrollBehavior.