我有一个Nuxt项目。当我从http://localhost:3000/catalog/postery更改路由到http://localhost:3000/catalog/postery/all?photos%5B%5D=262时,我的页面会滚动到顶部,只有在我的路由改变之后
我的文件scrollBehavior.js:
export default async function (to, from, savedPosition) {
if (
(to.path.indexOf("/catalog/") !== -1 &&
to.path.indexOf("/all") === -1 &&
Object.keys(to.query).length > 0) ||
(to.path.indexOf("/search") !== -1 && Object.keys(to.query).length > 0) ||
(to.name === "product-type-id" && Object.keys(to.query).length > 0) ||
(from.name === "product-type-id" &&
to.name === "product-type-id" &&
to.params.type != from.params.type)
) {
return;
}
if (to.path.indexOf("/catalog/") !== -1 && savedPosition != null) {
return { x: 0, y: savedPosition.y };
}
return { x: 0, y: 0 };
}
我如何在更改路由之前防止页面滚动到顶部?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号