Commit b882bc7b by Wee

fix(scroll): clear scroll after restore

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