1.react中路由跳轉后頁面不置頂問題
問題: 從頁面A跳轉到頁面B,頁面A滾動到中間位置,跳轉后頁面B也會在中間位置
解決方法:在頂部組件的生命周期中進行判斷,例如
componentWillReceiveProps(nextProps){
//當路由切換到新頁面時置頂
if(this.props.location !== nextProps.location){
window.scrollTo(0,0)
}
}