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

After using router.push\replace asyncData not called on new page #3205

Closed
aldarund opened this Issue Apr 8, 2018 · 8 comments

Comments

Projects
3 participants
@aldarund
Collaborator

aldarund commented Apr 8, 2018

Version

v1.4.0

Reproduction link

https://glitch.com/edit/#!/poised-hardware

Steps to reproduce

https://poised-hardware.glitch.me/ - if you go index page u will see render error due to undefined variable. But index page only do router.push to /page2.
If u go directly to https://poised-hardware.glitch.me/page2 all renders fine.

What is expected ?

asyncData called and variable resolved so no error happened like when page accessed directly without router.push

What is actually happening?

render error due to undefined variable that should come from asyncData

This bug report is available on Nuxt.js community (#c6869)

@cmty cmty bot added the cmty:bug-report label Apr 8, 2018

@yoyo837

This comment has been minimized.

Contributor

yoyo837 commented Apr 9, 2018

asyncData is server only.

@aldarund

This comment has been minimized.

Collaborator

aldarund commented Apr 9, 2018

@yoyo since when it's server only ? It's not server only

@yoyo837

This comment has been minimized.

Contributor

yoyo837 commented Apr 9, 2018

@aldarund You are right.I will correct myself.

@Atinux

This comment has been minimized.

Member

Atinux commented Apr 10, 2018

Hi @aldarund

You cannot use $router.push or $router.replace inside fetch or asyncData. To understand more, these methods are called inside router.beforeEach. You need to call redirect.

Please see your example fixed: https://glitch.com/edit/#!/lying-ring?path=pages/index.vue:2:1

@aldarund

This comment has been minimized.

Collaborator

aldarund commented Apr 10, 2018

@Atinux thanks, that worked. Is it documented somewhere?

@Atinux

This comment has been minimized.

Member

Atinux commented Apr 10, 2018

It is not, it is pretty hard to document everything, you can find more about the context here: https://nuxtjs.org/api/context

@Atinux Atinux closed this Apr 10, 2018

@aldarund

This comment has been minimized.

Collaborator

aldarund commented Apr 17, 2018

@Atinux redirect works. but it seems to cause lose of store state. E.g. on first page i set some store variables, then redirect to second page. And on second page all set variables are lost.
https://glitch.com/edit/#!/furry-shop

@Atinux Atinux added this to Done in Bugs 🐞 Aug 8, 2018

@lock

This comment has been minimized.

lock bot commented Nov 2, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 2, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.