页面跳转时未滚动到顶部

This commit is contained in:
caishi 2021-05-10 18:03:23 +08:00
parent 191e79e05a
commit aef1451455
5 changed files with 21 additions and 13 deletions

View File

@ -80,16 +80,6 @@ const http500 = Loadable({
loader: () => import('./modules/500/http500'),
loading: Loading,
})
// const InfosIndex = Loadable({
// loader: () => import('./forge/users/Index'),
// loading: Loading,
// })
// 组织
// const OrganizeIndex = Loadable({
// loader: () => import('./forge/Team/Index'),
// loading: Loading,
// })
class App extends Component {
constructor(props) {
super(props);

View File

@ -59,7 +59,7 @@ export function initAxiosInterceptors(props) {
// TODO 避免重复的请求 https://github.com/axios/axios#cancellation
var
proxy = "http://localhost:3000"
proxy = "https://testforgeplus.trustie.net"
proxy = "https://forum.trustie.net"
const requestMap = {};
window.setfalseInRequestMap = function (keyName) {

View File

@ -39,6 +39,13 @@ class Index extends Component{
})
}
componentDidUpdate=()=>{
this.props.history.listen(()=>{
if (document.body.scrollTop || document.documentElement.scrollTop > 0) {
window.scrollTo(0, 0)
}
})
}
render(){
return(
<Switch {...this.props}>

View File

@ -27,7 +27,9 @@ const New = Loadable({
class Index extends Component {
componentDidUpdate=()=>{
this.props.history.listen(()=>{
if (document.body.scrollTop || document.documentElement.scrollTop > 0) {
window.scrollTo(0, 0)
}
})
}
render() {

View File

@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect } from "react";
import { TPMIndexHOC } from "../modules/tpm/TPMIndexHOC";
import { SnackbarHOC } from "educoder";
import { CNotificationHOC } from "../modules/courses/common/CNotificationHOC";
@ -31,6 +31,15 @@ const Blocks = Loadable({
});
function Index(props) {
const history = props.history;
useEffect(()=>{
history.listen(()=>{
if (document.body.scrollTop || document.documentElement.scrollTop > 0) {
window.scrollTo(0, 0)
}
})
},[history])
return (
<div className="newMain">
<UserInfo {...props}></UserInfo>