组件之间进行页面跳转时,滚动条未返回至顶部

This commit is contained in:
caishi 2021-05-10 17:24:49 +08:00
parent b70dd5928e
commit 6a6f0ca784
5 changed files with 16 additions and 8 deletions

4
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "forge",
"version": "0.1.0",
"version": "3.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -2065,7 +2065,7 @@
},
"babel-polyfill": {
"version": "6.26.0",
"resolved": "https://registry.npm.taobao.org/babel-polyfill/download/babel-polyfill-6.26.0.tgz",
"resolved": "https://registry.nlark.com/babel-polyfill/download/babel-polyfill-6.26.0.tgz",
"integrity": "sha1-N5k3q8Z9eJWXCtxiHyhM2WbPIVM=",
"dev": true,
"requires": {

View File

@ -124,12 +124,6 @@ class App extends Component {
componentDidMount() {
document.title = "loading...";
this.disableVideoContextMenu();
history.listen(() => {
this.forceUpdate()
const $ = window.$
$("html").animate({ scrollTop: $('html').scrollTop() - 0 })
});
initAxiosInterceptors(this.props);
this.getAppdata();

View File

@ -31,6 +31,14 @@ const Infos = Loadable({
loading: Loading,
});
class Index extends Component {
componentDidUpdate=()=>{
this.props.history.listen(()=>{
if (document.body.scrollTop || document.documentElement.scrollTop > 0) {
window.scrollTo(0, 0)
}
})
}
render() {
return (
<div className="newMain clearfix">

View File

@ -67,6 +67,11 @@ class Infos extends Component {
if(prevUser && username && prevUser !== username){
this.fetchUser();
}
this.props.history.listen(()=>{
if (document.body.scrollTop || document.documentElement.scrollTop > 0) {
window.scrollTo(0, 0)
}
})
}
fetchUser = () => {

View File

@ -13,6 +13,7 @@ configureUrlQuery({ history });
window.__useKindEditor = false;
const render = (Component) => {
ReactDOM.render(
<AppContainer >