mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
fix(vue-app): use browser to handle scrolling position on page reload and back-navigation from other sites (#5080)
This commit is contained in:
parent
9bf3b32a7b
commit
ee87f4ca82
@ -86,7 +86,21 @@ Vue.use(Router)
|
|||||||
const scrollBehavior = <%= serializeFunction(router.scrollBehavior) %>
|
const scrollBehavior = <%= serializeFunction(router.scrollBehavior) %>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
if (process.client) {
|
if (process.client) {
|
||||||
window.history.scrollRestoration = 'manual'
|
if ('scrollRestoration' in window.history) {
|
||||||
|
window.history.scrollRestoration = 'manual'
|
||||||
|
|
||||||
|
// reset scrollRestoration to auto when leaving page, allowing page reload
|
||||||
|
// and back-navigation from other pages to use the browser to restore the
|
||||||
|
// scrolling position.
|
||||||
|
window.addEventListener('beforeunload', () => {
|
||||||
|
window.history.scrollRestoration = 'auto'
|
||||||
|
})
|
||||||
|
|
||||||
|
// Setting scrollRestoration to manual again when returning to this page.
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
window.history.scrollRestoration = 'manual'
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const scrollBehavior = function (to, from, savedPosition) {
|
const scrollBehavior = function (to, from, savedPosition) {
|
||||||
// if the returned position is falsy or an empty object,
|
// if the returned position is falsy or an empty object,
|
||||||
|
Loading…
Reference in New Issue
Block a user