DEV Community

Nuxt.js Smooth Scrolling with Hash Links

Dimer Bwimba on February 21, 2021

As of Nuxt.js release 1.4.2, the default scroll behavior does not work as expected when using element ID's as hash links in routes (example: about-...
Collapse
 
arukomp profile image
Arunas Skirius

Thanks @dimer191996 , this was very useful!! πŸ’ͺ

Collapse
 
bayyash profile image
Info Comment hidden by post author - thread only accessible via permalink

There are some issues with this article ... πŸ€”

First: I found same article posted on 2018.09.04 by @ZachCardoza and here is the url for it zachcardoza.com/post/nuxtjs-smooth...

Second: it is for old version of NuxtJS current Nuxt version is 2.15.3

Third: router.scrollBehavior property is deprecated in favor of using ~/app/router.scrollBehavior.js file, learn more: nuxtjs.org/api/configuration-route...

Try to write your own articles or at lease give credits to the original authors,,,,

Collapse
 
katieadamsdev profile image
Katie Adams

Hey, great work on this article. I'm working on a Nuxt project atm and this will be super useful!

Collapse
 
dimer191996 profile image
Dimer Bwimba

wow you can't image how awesome I feel when you say that. Send me your GitHub so i can take a look at your project. :)

Collapse
 
katieadamsdev profile image
Katie Adams

I'm glad it was appreciated! It's a work project so unfortunately we don't have a public repo for obvious reasons. I'll see if I can find a personal project to use it on some time though!

Collapse
 
mrehsanakbarzadeh profile image
Ehsan Akbarzadeh

tnx bro it's super usefull ❀️

Collapse
 
dimer191996 profile image
Dimer Bwimba

happy coding

Collapse
 
lucaargentieri profile image
Luca Argentieri

Wow, Thanks

I got this error when there is the anchor in url path, you know why?

Uncaught (in promise) Error: [vue-router] TypeError: Cannot read properties of undefined (reading 'behavior')

Collapse
 
ed3899 profile image
Eduardo Casanova • Edited

You are f"#$"n smart! This was killing me for hours. Can't believe they still haven't internally fix this issue. Specially with static pages and hash navigation, this is a nuisance.

Thx man

Collapse
 
dimer191996 profile image
Dimer Bwimba

Same here!, I don't really know what they're waiting for . Thanks To you man for reading it !

Collapse
 
prostoleo profile image
prostoleo

Thank you! You've really helped me out πŸ‘

Collapse
 
jamaluddinrumi profile image
Jamaluddin Rumi

thank you very much

Collapse
 
bayyash profile image
Info Comment hidden by post author - thread only accessible via permalink
Bashar Ayyash
Collapse
 
mod7ex profile image
Mourad EL CADI

thanks man)

Some comments have been hidden by the post's author - find out more