1. 程式人生 > >代碼清除頁面切換過渡現象

代碼清除頁面切換過渡現象

return prop class div ont render page 當前 展示

所謂的頁面切換過渡現象,指的是假如我現在瀏覽了A頁面,然後去瀏覽B頁面,但是在B頁面的被渲染的那一瞬間,上一個被瀏覽的A頁面,會閃現一下,瞬間很短,只有仔細觀察,才能看出,但是這個不解決,也不會影響用戶體驗。我個人感覺還是解決一下為好,這樣可以讓用戶體驗效果更好。下面是我的解決方案,放在一個例子裏:

render() {
const { currentPromotionUser } = this.promoption;

// 如果用戶與尚未加入推廣計劃,則默認展示協議界面
const children = ((isJoined) => {
/**
* isJoined是bool值,isJoined===true時,顯示home頁面,isJoined===false時,顯示agreement頁面。

* isJoined==null,是為了在即將渲染一個頁面前,先渲染一個空頁面,目的是不讓上一個瀏覽的頁面在當前頁面刷新時出現閃現的過程。
*/
if (isJoined == null) {
return null;
} else if (isJoined === true) {
return this.props.children;
} else {
return <Agreement/>
}
})(_.get(currentPromotionUser, ‘isJoined‘, null));

return (

<div className="page-group">
{children}
</div>
)
}


其實我個人更感覺
if (isJoined == null) {return null;}這句代碼,是做了一個假的數據清除,哈哈哈哈,因為它只是先渲染了一個空頁面來遮擋著上一個被瀏覽過的頁面

代碼清除頁面切換過渡現象