@@ -185,7 +185,7 @@ class App extends Component<AppProps, AppState> {
185185 this . _defaultDocumentTitle = document . title
186186 this . updateKey ( )
187187
188- window . addEventListener ( 'hashchange ' , this . updateKey , false )
188+ window . addEventListener ( 'popstate ' , this . updateKey , false )
189189
190190 // TODO: Replace with the Responsive component later
191191 // Using this method directly for now instead to avoid a call to findDOMNode
@@ -225,6 +225,13 @@ class App extends Component<AppProps, AppState> {
225225 } )
226226 } )
227227 . catch ( errorHandler )
228+
229+ const [ page ] = this . getPathInfo ( )
230+ const isHomepage = page === 'index' || typeof page === 'undefined'
231+ if ( isHomepage ) {
232+ this . setState ( { showMenu : false } )
233+ }
234+
228235 document . addEventListener ( 'focusin' , this . handleFocusChange )
229236 }
230237
@@ -242,7 +249,7 @@ class App extends Component<AppProps, AppState> {
242249 componentWillUnmount ( ) {
243250 //cancel ongoing requests
244251 this . _controller ?. abort ( )
245- window . removeEventListener ( 'hashchange ' , this . updateKey , false )
252+ window . removeEventListener ( 'popstate ' , this . updateKey , false )
246253
247254 if ( this . _mediaQueryListener ) {
248255 this . _mediaQueryListener . remove ( )
@@ -261,13 +268,51 @@ class App extends Component<AppProps, AppState> {
261268 }
262269
263270 getPathInfo = ( ) => {
264- const { hash } = window . location
271+ const { hash, pathname } = window . location
272+
273+ // Case 1: Old hash-based routing (hash contains the main content)
274+ const cleanPath = pathname . replace ( / ^ \/ + | \/ + $ / g, '' )
275+ const pathSegments = cleanPath . split ( '/' )
265276
266- const path = hash && hash . split ( '/' )
277+ // Check if the pathname is just a base path (ends with slash or has no meaningful final segment)
278+ const hasSubstantialPathname =
279+ pathSegments . length > 0 &&
280+ pathSegments [ pathSegments . length - 1 ] !== '' &&
281+ ! pathSegments . every ( ( seg ) => seg === '' )
282+
283+ // If it's just a base path with no hash, treat as homepage
284+ if ( ( ! hasSubstantialPathname || pathname . endsWith ( '/' ) ) && ! hash ) {
285+ return [ 'index' ] // homepage
286+ }
267287
268- if ( path ) {
269- const [ page , id ] = path . map ( ( entry ) => decodeURI ( entry . replace ( '#' , '' ) ) )
270- return [ page , id ]
288+ if (
289+ hash &&
290+ ( ! hasSubstantialPathname || pathname . endsWith ( '/' ) ) &&
291+ hash . startsWith ( '#' ) &&
292+ ! hash . startsWith ( '##' )
293+ ) {
294+ const path = hash . split ( '/' )
295+ if ( path ) {
296+ const [ page , id ] = path . map ( ( entry ) =>
297+ decodeURI ( entry . replace ( '#' , '' ) )
298+ )
299+ return [ page , id ]
300+ }
301+ }
302+ // Case 2: New clean URL routing (pathname contains the main content)
303+ else {
304+ if ( pathSegments . length > 0 && pathSegments [ 0 ] !== '' ) {
305+ // Get the page from the last segment of the path
306+ const page = pathSegments [ pathSegments . length - 1 ]
307+ // If there's a hash that's not at the beginning (like #Guidelines), use it as ID
308+ let id = undefined
309+ if ( hash && hash . startsWith ( '##' ) ) {
310+ id = decodeURI ( hash . replace ( '##' , '' ) )
311+ } else if ( hash && ! hash . startsWith ( '#/' ) ) {
312+ id = decodeURI ( hash . replace ( '#' , '' ) )
313+ }
314+ return [ page , id ]
315+ }
271316 }
272317 return [ ]
273318 }
@@ -289,7 +334,6 @@ class App extends Component<AppProps, AppState> {
289334
290335 updateKey = ( ) => {
291336 const [ page , _id ] = this . getPathInfo ( )
292-
293337 if ( page ) {
294338 this . setState (
295339 ( { key, showMenu } ) => ( {
0 commit comments