Commit b882bc7b by Wee

fix(scroll): clear scroll after restore

parent 1bfdd8f3
......@@ -119,9 +119,9 @@ class Route extends React.Component {
// 是正常的显示渲染
console.log(this.liveState)
if (this.liveState === NORMAL_RENDER_MATCH) {
console.log('1111')
this.showRoute()
this.restoreScroll()
this.clearScroll()
}
// 正常渲染标记 DOM
......@@ -131,9 +131,7 @@ class Route extends React.Component {
}
componentWillUnmount() {
if (this.doesRouteEnableLive()) {
this.scrollPosBackup = null
}
this.clearScroll()
}
doesRouteEnableLive() {
......@@ -203,8 +201,8 @@ class Route extends React.Component {
// 隐藏 DOM 并保存 scroll
hideRoute() {
console.log('--- hide route ---')
if (this.routeDom && this.routeDom.style.display !== 'none') {
console.log('--- hide route ---')
this.previousDisplayStyle = this.routeDom.style.display
this.routeDom.style.display = 'none'
}
......@@ -218,7 +216,7 @@ class Route extends React.Component {
}
// 保存离开前的 scroll
saveScroll = () => {
saveScroll() {
if (this.routeDom && this.scrollPosBackup === null) {
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
const scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft
......@@ -228,7 +226,7 @@ class Route extends React.Component {
}
// 恢复离开前的 scroll
restoreScroll = () => {
restoreScroll() {
const scroll = this.scrollPosBackup
console.log(scroll)
if (scroll && this.routeDom) {
......@@ -236,6 +234,13 @@ class Route extends React.Component {
}
}
// 清除 scroll
clearScroll() {
if (this.doesRouteEnableLive()) {
this.scrollPosBackup = null
}
}
// 正常渲染 component 或 render
renderRoute(component, render, props, match) {
console.log(match)
......
{
"name": "react-live-route",
"version": "1.1.13",
"version": "1.1.14",
"description": "A living route for react-router-v4",
"repository": "fi3ework/react-live-route",
"license": "MIT",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment