mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +08:00
🐛 Fix scroll to initial anchor on page load and scroll to top on router change.
chore: Use destroy replace disable.
This commit is contained in:
parent
5b8867439a
commit
8539cf6879
@ -68,6 +68,7 @@ export default class MainContent extends Component {
|
||||
|
||||
componentDidMount() {
|
||||
this.componentDidUpdate();
|
||||
window.addEventListener('load', this.handleInitialHashOnLoad);
|
||||
}
|
||||
|
||||
static getDerivedStateFromProps(props, state) {
|
||||
@ -87,13 +88,21 @@ export default class MainContent extends Component {
|
||||
this.bindScroller();
|
||||
}
|
||||
if (!window.location.hash && prevLocation.pathname !== location.pathname) {
|
||||
document.documentElement.scrollTop = 0;
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
// when subMenu not equal
|
||||
if (get(this.props, 'route.path') !== get(prevProps, 'route.path')) {
|
||||
// reset menu OpenKeys
|
||||
this.handleMenuOpenChange();
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.scroller.destroy();
|
||||
window.removeEventListener('load', this.handleInitialHashOnLoad);
|
||||
}
|
||||
|
||||
handleInitialHashOnLoad() {
|
||||
setTimeout(() => {
|
||||
if (!window.location.hash) {
|
||||
return;
|
||||
@ -107,10 +116,6 @@ export default class MainContent extends Component {
|
||||
}, 0);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.scroller.disable();
|
||||
}
|
||||
|
||||
getMenuItems(footerNavIcons = {}) {
|
||||
const { themeConfig } = this.props;
|
||||
const {
|
||||
@ -165,7 +170,7 @@ export default class MainContent extends Component {
|
||||
|
||||
bindScroller() {
|
||||
if (this.scroller) {
|
||||
this.scroller.disable();
|
||||
this.scroller.destroy();
|
||||
}
|
||||
require('intersection-observer'); // eslint-disable-line
|
||||
const scrollama = require('scrollama'); // eslint-disable-line
|
||||
|
Loading…
Reference in New Issue
Block a user