Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial route appears twice in browser history #9111

Closed
cpaczek opened this issue Apr 5, 2021 · 7 comments · Fixed by #9201
Closed

Initial route appears twice in browser history #9111

cpaczek opened this issue Apr 5, 2021 · 7 comments · Fixed by #9201

Comments

@cpaczek
Copy link

cpaczek commented Apr 5, 2021

Versions

  • nuxt: 2.15.4
  • node: 12.18.3

Reproduction

use npm init nuxt-app my-app-name to create a new app and leave everything defaults except change yarn to npm.

run npm run dev

go to google.com

paste in localhost:3000

It requires 2 clicks of the back button in order to get to google.com.

What is actually happening?

Because of how html5 history API works I believe (not entirely sure) nuxt is loading the index.html (which pushes once to history) then changes the route to the /newpage and pushes another entry to the session history. This causes you to have to use back twice to get to the original page.

What is Expected?

This is to be expected behavior when using history mode however I think the default mode should be changed from 'history' to 'abstract'

This is really up to the core team to decide if they want to change the default mode. Currently, in the docs it says that you should not change this mode due to server-side rendering however on the vue documentation it says abstract mode should be used for server-side rendering (and is the default).

I don't know exactly how abstract differs from history but from my limited testing, I don't see any downside.

If the default does not get changed then I think that this solution should be somewhere more prominent in the docs.

@edisoft00
Copy link

edisoft00 commented Apr 17, 2021

My project is also having this problem, in production also happens to me.

I have solved it using version 2.15.3 of NUXT

@danielroe danielroe changed the title Changing the default history mode to 'abstract' from 'history' to prevent double history push Initial route appears twice in browser history Apr 23, 2021
@qinxuanxin
Copy link

qinxuanxin commented Apr 26, 2021

ME TOO. HELP HELP HELP!!! PLEASE SEND ME A MESSAGE!! I NEED SSR RENDER I NEED HISTORY MODE

@cpaczek
Copy link
Author

cpaczek commented Apr 26, 2021

@qinxuanxin is there a reason you can't use abstract mode. From my experience they function almost identically.

@qinxuanxin
Copy link

@qinxuanxin is there a reason you can't use abstract mode. From my experience they function almost identically.
Thank you,I have solved the problem by using a lower version of Nuxt.
Most of the old code will operate the URL on the browser,so if i change to abstract mode, it will cost me.

@cpaczek
Copy link
Author

cpaczek commented Apr 27, 2021

I have narrow this down to #9010 as reverting this 1 line of code will fix the double history push issue. As I am fairly new to nuxt I am not sure how to implement a fix to issue #9009 without breaking changes while still preventing a double history push. Thought this might be helpful. @enwin

For people who are having this issue currently, the fixes are downgrading to version 2.15.3 or using history: abstract within your nuxt config.

@enwin
Copy link

enwin commented Apr 27, 2021

Hi @cpaczek. Thanks for narrowing it down. The linked PR should fix your issue. If you can test it I'd like your feedback on it.

@ezawadzki
Copy link

Hi,
This error is still present in Nuxt 3.
Config:
Nuxt : 3.6.5
Node : 16.15.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants