-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Vue-router, transitions and scrollBehavior - Page jumping back to top or changing scroll location #1466
Comments
This example might be useful: https://github.com/vuejs/vue-router/blob/dev/examples/scroll-behavior/app.js |
I'm also having this issue and looking for a solution |
same problem here, scroll behavior should be invoked not sooner than leave transition finishes, I will probably temporarly fix it with disabling scroll behavior and emulate proper behavior manually EDIT*** |
I'm also having this issue and looking for a solution |
I had this same problem. It looks like modern browsers set the scroll to savedPosition immediately when you navigate using the browser buttons, so returning a promise from scrollBehavior does not fix the flickering issue entirely. In order to prevent the browser's default behavior, do this:
Perhaps this should be included in the docs or should be set by the router by default? |
Use something along this lines: <q-page-container>
<transition enter-active-class="animated fadeIn" leave-active-class="animated fadeOut" mode="out-in" :duration="200" @after-leave="$root.$emit('triggerScroll')">
<router-view />
</transition>
</q-page-container> In router initialization: const Router = new VueRouter({
...
scrollBehavior: (to, from, savedPosition) => new Promise((resolve) => {
const position = savedPosition || {};
if (!savedPosition) {
if (to.hash) {
position.selector = to.hash;
}
if (to.matched.some((m) => m.meta.scrollToTop)) {
position.x = 0;
position.y = 0;
}
}
Router.app.$root.$once('triggerScroll', () => {
Router.app.$nextTick(() => resolve(position));
});
}),
routes,
}); |
Why is this closed? I'm getting the same issue with the <transition element without using VueRouters |
Agreed I'm also having this issue still. |
Did you try this approach example @cybercussion ? |
@nothingismagick I used tkiley's approach and its good in Safari/Chrome. I think my cache was sticking. |
I think such information should be placed in documentation |
This is not working for me. Can you please give me an example ? This is my code :
|
Please head to VueRouter for this, thank you. |
There is no support from Vue, I even tried the documentation Vue Router - Scroll Behaviour but no success. To every page I navigate back, the page is scrolled to top. Quasar should provide some support on this. |
It's up to you to decide what you need. And Google if full of examples: https://www.google.com/search?q=vue-router+scrollBehaviour+example&pws=0&gl=us&gws_rd=cr Really, the issues on GitHub are not proxies for people who are too lazy to search: |
Good news, if you're experiencing such a problem, just go your favorite code editor(I use VSCode) and search below words over in your project: |
There is currently a problem with the vue-router and vue-transitions (outside of Quasar) that causes pages to jump back to the top before transitions and also to change scroll location when doing popstate navigations (browser back and forward buttons. Here are some details, please post comments or questions on this topic here.
vue-router with scrollBehavior currently works when there are NO transitions. The users scroll position will be retained between popstate navigations.
Additionally, to ensure that the component state is retained (eg form field data, opened tabs, etc.) the keep-alive must be used
For transitions on routes, there is a new Async scrollBehavior, but there are still some issues that are currently being worked on by the vue team. Here is the current partial solution. Note that the scrollBehavior delay is 1 second and the transition is 0.5s to emphasize the mechanics in play here.
References:
https://router.vuejs.org/en/advanced/scroll-behavior.html
The text was updated successfully, but these errors were encountered: