11import * as React from 'react'
2- import { Switch , Link , Route , Redirect } from 'react-router-dom'
2+ import { Switch , Link , Route , Redirect , useLocation } from 'react-router-dom'
33import cx from 'classnames'
44import { ifDev , ifProd , ifPrerender } from 'crd-client-utils'
55import Menu from '../component/Menu'
@@ -19,11 +19,10 @@ const { useState, useEffect } = React
1919const SubMenu = Menu . SubMenu
2020
2121function BasicLayout ( {
22- location,
2322 routeData,
24- menuSource,
25- indexProps,
23+ menuSource
2624} ) {
25+ const location = useLocation ( )
2726 const { pathname } = location
2827 const {
2928 user,
@@ -248,21 +247,24 @@ function BasicLayout({
248247 >
249248 < Switch >
250249 { /* see https://reacttraining.com/react-router/web/api/Redirect/exact-bool */ }
251- < Redirect exact from = { ifAddPrefix ? `/${ repo } ` : `/` } to = { ifAddPrefix ? `/${ repo } /${ defaultPath } ` : `/${ defaultPath } ` } />
250+ < Route
251+ exact
252+ path = { ifAddPrefix ? `/${ repo } ` : `/` }
253+ render = { ( ) => < Redirect to = { ifAddPrefix ? `/${ repo } /${ defaultPath } ` : `/${ defaultPath } ` } /> }
254+ />
252255 { routeData . map ( ( item ) => {
253256 const { path, mdconf, component } = item
254257 const { abbrlink } = mdconf
255258 const enhancePath = abbrlink ? `/${ abbrlink } ` : path
259+ const Comp = component
256260 return (
257261 < Route
258262 key = { enhancePath }
259263 exact
260264 path = { ifAddPrefix ? `/${ repo } ${ enhancePath } ` : enhancePath }
261- render = { ( ) => {
262- const Comp = component
263- return < Comp { ...item } />
264- } }
265- />
265+ >
266+ < Comp { ...item } />
267+ </ Route >
266268 )
267269 } ) }
268270 {
@@ -272,20 +274,20 @@ function BasicLayout({
272274 key = '/tags'
273275 exact
274276 path = { ifAddPrefix ? `/${ repo } /tags` : '/tags' }
275- render = { ( ) => < Tags /> }
276- />
277+ >
278+ < Tags />
279+ </ Route >
277280 < Route
278281 key = '/tags/:name'
279282 path = { ifAddPrefix ? `/${ repo } /tags/:name` : '/tags/:name' }
280- render = { ( { match } ) => {
281- const { name } = match . params
282- return < Tags name = { name } />
283- } }
284- />
283+ >
284+ < Tags />
285+ </ Route >
285286 </ >
286287 : null
287288 }
288- < Redirect to = { ifAddPrefix ? `/${ repo } /404` : `/404` } />
289+ { /* Todo: follow up how to use Redirect to back up the rest of route. */ }
290+ { /* <Redirect path='/' to={ifAddPrefix ? `/${repo}/404` : `/404`} /> */ }
289291 </ Switch >
290292 { renderPageFooter ( ) }
291293 </ div >
0 commit comments