react跳转路由后,展示的位置是上个页面浏览的位置。解决的思路是强制回到顶部
//在父页面里加入该行代码即可
componentWillUpdate(){
document.getElementById('root').scrollIntoView(true);//为ture返回顶部,false为底部
}
如果使用的是单独的页面,则需要在单独的所有页面里加入如下代码:
//在单独的页面里使用will即可
componentWillMount(){
document.getElementById('root').scrollIntoView(true);//为ture返回顶部,false为底部
}