Answer the question
In order to leave comments, you need to log in
How to make a proper smart back button in VueJS?
I rummaged through half the Internet in search of an answer, and everywhere I did not find anything specific, or suitable. I am reaching out to the community with my question. Perhaps someone has already faced such a dilemma.
I can't figure out how to properly make a BACK button in a VUE JS application with a VUE ROUTER connected.
I will give a simple example on the blog.
There is a list of blog posts at URL : /posts
There is a blog post view page URL : /post/:id
The post view page has a back button. According to the VUE JS documentation, this is made simple
And everything seems to be fine, but if we go directly to the post view??? Where will it lead ??? That's right - nowhere. The option is not suitable, since we need to go back to the list of blog posts.router.go(-1)
router.go(-1)
Next option, specify directly
<router-link to="/posts" class="backlink">
Назад
</router-link>
. So good, everything seems to be great. Now the problem with directly following the link to the post is solved, only another problem appears. Scroll positioning. When we go(-1) we save all the posts that have been loaded into the list, and when we go to="/posts" the component reloads the posts and positions itself at the top. Okay, positioning, the component just starts loading data again. Answer the question
In order to leave comments, you need to log in
So good, everything seems to be great. Now the problem with directly following the link to the post is solved, only another problem appears. Scroll positioning. When we go(-1) we save all the posts that have been loaded into the list, and when we go to="/posts" the component reloads the posts and positions itself at the top. Okay, positioning, the component just starts loading data again.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question