[英]vue-router:how to not `saveScrollPosition`
In my case, I have used vue
and vue-router
. 就我而言,我使用了
vue
和vue-router
。 I have fould a problem that somewhat the saveScrollPostion
property can not work well. 我可能会遇到一个问题,就是
saveScrollPostion
属性有些无法正常工作。
This is my codes: 这是我的代码:
router.js
export default router => {
"use strict"
router.map({
//'/': {
// component: null
//},
'/blogs': {
component: require('./views/ArticleListPage.vue'),
subRoutes: {
'/': {
component: require('./components/ArticleList/ArticleListSection.vue'),
},
'/tag/:name': {
component: require('./components/ArticleList/ArticleListSection.vue'),
name: 'tag'
},
'/classification/:name': {
component: require('./components/ArticleList/ArticleListSection.vue'),
name: 'classification'
}
}
},
'/projects': {
component: require('./views/ProjectPage.vue')
},
'/about': {
component: require('./views/AboutPage.vue')
},
'/p/:id': {
component: require('./views/ArticlePage.vue')
},
'*': {
component: require('./views/NotFound.vue')
}
});
router.beforeEach(()=>{
});
In index.js
, there are two settings in the Router
instance: 在
index.js
, Router
实例中有两个设置:
const router = new Router({
history: true,
saveScrollPosition: false
});
The problem is: if going to any of the /p/:id
route and scrolling the page down, you will find the previous page also scrolled after going back. 问题是:如果转到任何
/p/:id
路由并将页面向下滚动,您会发现上一页在返回后也已滚动。
I have read vue-router documentation, it says the saveScrollPostion 我已经阅读了vue-router文档,上面写着saveScrollPostion
might not work as expected if your has transition effects.
如果您具有过渡效果,则可能无法按预期工作。
When deleting the setting, or just changing the saveScrollPosition
to false, the problem is still there. 删除设置或仅将
saveScrollPosition
更改为false时,问题仍然存在。
I guess it is the router.map
method I wrote that causes the wrong result. 我猜这是我编写的
router.map
方法导致错误的结果。
I also wonder whether there is any bug in my project codes instead of the vue-router
settings that leads to this problem. 我还想知道我的项目代码中是否存在任何错误,而不是导致该问题的
vue-router
设置。
Further more, I haven't written any transition
settings between route transitions. 此外,我还没有编写路线转换之间的任何
transition
设置。
Thank all of you for answering my question. 感谢大家回答我的问题。
try to watch for $route property of Vue, eg: 尝试观察Vue的$ route属性,例如:
watch: {
$route: function() {
window.scrollTo(0,0);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.