11import * as React from 'react'
22import { Switch , Link , Route , Redirect } from 'react-router-dom'
33import cx from 'classnames'
4+ import { ifDev , ifProd , ifPrerender } from 'crd-client-utils'
45import Menu from '../component/Menu'
56import Icon from '../component/Icon'
67import Affix from '../component/Affix'
78import Header from '../component/Header'
89import Footer from '../component/Footer'
910import languageMap from '../language'
10- import { isMobile , ifAddPrefix , ifProd , ifPrerender } from '../utils'
11+ import { isMobile , ifAddPrefix } from '../utils'
1112import { getOpenSubMenuKeys } from './utils'
1213import logo from '../crd.logo.svg'
1314import styles from './index.less'
@@ -21,11 +22,15 @@ function BasicLayout({
2122 routeData,
2223 menuSource,
2324 indexProps,
25+ // render area
26+ pointRender
2427} ) {
2528 const { pathname } = location
2629 const { user, repo, branch = 'main' , language = 'en' , menuOpenKeys } = DOCSCONFIG || { }
2730 const [ inlineCollapsed , setInlineCollapsed ] = useState ( true )
2831 const [ selectedKey , setSelectedKey ] = useState ( '' )
32+ const [ monted , setMounted ] = useState ( false )
33+ const [ routeChanged , setRoutedChanged ] = useState ( false )
2934 const curOpenKeys = getOpenSubMenuKeys ( {
3035 pathname,
3136 menuSource,
@@ -59,6 +64,17 @@ function BasicLayout({
5964 setSelectedKey ( newPathName || defaultPath )
6065 } , location . pathname )
6166
67+ useEffect ( ( ) => {
68+ setMounted ( true )
69+ } , [ ] )
70+
71+ useEffect ( ( ) => {
72+ const { pathname } = location
73+ if ( monted ) {
74+ setRoutedChanged ( true )
75+ }
76+ } , location . pathname )
77+
6278 const scrollToTop = ( ) => {
6379 document . body . scrollTop = 0
6480 document . documentElement . scrollTop = 0
@@ -229,6 +245,7 @@ function BasicLayout({
229245 )
230246 }
231247
248+ // Target: The first screen not to do renderContent logic. The second screen do.
232249 const renderContent = ( ) => {
233250 return (
234251 < div
@@ -261,26 +278,39 @@ function BasicLayout({
261278 </ div >
262279 )
263280 }
281+
282+ console . log ( 'routeChanged' , routeChanged )
264283 return (
265- < div className = { styles . wrapper } >
266- < Header
267- logo = { logo }
268- href = { ifAddPrefix ? `/${ repo } ` : `/` }
269- location = { location }
270- indexProps = { indexProps }
271- menuSource = { menuSource }
272- />
273- < div
274- className = { cx ( styles . wrapperContent , {
275- [ styles . wrapperMobile ] : isMobile ,
276- } ) }
277- >
278- { renderPageHeader ( ) }
279- { renderMenuContainer ( ) }
280- { renderContent ( ) }
281- < Footer inlineCollapsed = { inlineCollapsed } />
282- </ div >
283- </ div >
284+ < >
285+ {
286+ // pointRender === 'menu' && !routeChanged
287+ // prod render
288+ // ? renderMenuContainer()
289+ // pre & dev render
290+ // : <div className={styles.wrapper}>
291+ < div className = { styles . wrapper } >
292+ < Header
293+ logo = { logo }
294+ href = { ifAddPrefix ? `/${ repo } ` : `/` }
295+ location = { location }
296+ indexProps = { indexProps }
297+ menuSource = { menuSource }
298+ />
299+ < div
300+ className = { cx ( styles . wrapperContent , {
301+ [ styles . wrapperMobile ] : isMobile ,
302+ } ) }
303+ >
304+ { renderPageHeader ( ) }
305+ { /* <div id="menuPosition"> */ }
306+ { renderMenuContainer ( ) }
307+ { /* </div> */ }
308+ { renderContent ( ) }
309+ < Footer inlineCollapsed = { inlineCollapsed } />
310+ </ div >
311+ </ div >
312+ }
313+ </ >
284314 )
285315}
286316
0 commit comments