nuxt-community / router-module

Nuxt 2 module to use router.js instead of pages/ directory.
MIT License
401 stars 28 forks source link

Scroll position #56

Closed Frankwarnaar closed 5 years ago

Frankwarnaar commented 5 years ago

Version

v1.4.0

Reproduction link

https://github.com/Frankwarnaar/nuxt-router-scrollposition-issue-demo

Steps to reproduce

Navigate to https://quizzical-villani-0e65e2.netlify.com (a deploy of the repo I provided). Scroll a bit down and then click the Other page link. Then click browser back.

What is expected ?

The scroll position should be the same as before leaving the page.

What is actually happening?

The scroll position is reset.

Additional comments

I'm running with the keepDefaultRouter option set to true. My router can be found in src/router.js. I've been trying to debug the issue, by providing a scrollPosition function to my router. Somehow the savedPosition argument was always { x: 0, y: 0 }, .

This bug report is available on Nuxt community (#c42)
ricardogobbosouza commented 5 years ago

@Frankwarnaar It is actually a problem with vue-router when it boots twice with mode history.

Frankwarnaar commented 5 years ago

Thank you for your quick response! Putting mode: hash in my nuxt config and then using mode: history when creating my custom router seems to be a workaround indeed.

ricardogobbosouza commented 5 years ago

Yes, it's an alternative. I'll see with the team nuxt to instantiate just once the vue-router

Frankwarnaar commented 5 years ago

Great! It seems to be the case that I was a bit over enthusiastic. In development the described workaround did work, but when running nuxt generate, no routes were generated anymore.

ricardogobbosouza commented 5 years ago

@Frankwarnaar see v1.5.0 add new parameter routerOptions

https://github.com/nuxt-community/router-module#accessing-default-router