11import * as React from 'react' ;
22import { Route , RouteComponentProps , Switch } from 'react-router-dom' ;
3- import { accessibleRouteChangeHandler } from '@app/utils/utils' ;
43import { Dashboard } from '@app/Dashboard/Dashboard' ;
54import { Support } from '@app/Support/Support' ;
65import { GeneralSettings } from '@app/Settings/General/GeneralSettings' ;
@@ -18,7 +17,6 @@ export interface IAppRoute {
1817 exact ?: boolean ;
1918 path : string ;
2019 title : string ;
21- isAsync ?: boolean ;
2220 routes ?: undefined ;
2321}
2422
@@ -40,7 +38,6 @@ const routes: AppRouteConfig[] = [
4038 {
4139 component : Support ,
4240 exact : true ,
43- isAsync : true ,
4441 label : 'Support' ,
4542 path : '/support' ,
4643 title : 'PatternFly Seed | Support Page' ,
@@ -69,27 +66,32 @@ const routes: AppRouteConfig[] = [
6966// a custom hook for sending focus to the primary content container
7067// after a view has loaded so that subsequent press of tab key
7168// sends focus directly to relevant content
72- const useA11yRouteChange = ( isAsync : boolean ) => {
69+ const useA11yRouteChange = ( ) => {
7370 const lastNavigation = useLastLocation ( ) ;
7471 React . useEffect ( ( ) => {
75- if ( ! isAsync && lastNavigation !== null ) {
76- routeFocusTimer = accessibleRouteChangeHandler ( ) ;
72+ if ( lastNavigation !== null ) {
73+ routeFocusTimer = window . setTimeout ( ( ) => {
74+ const mainContainer = document . getElementById ( 'primary-app-container' ) ;
75+ if ( mainContainer ) {
76+ mainContainer . focus ( ) ;
77+ }
78+ } , 50 ) ;
7779 }
7880 return ( ) => {
7981 window . clearTimeout ( routeFocusTimer ) ;
8082 } ;
81- } , [ isAsync , lastNavigation ] ) ;
83+ } , [ lastNavigation ] ) ;
8284} ;
8385
84- const RouteWithTitleUpdates = ( { component : Component , isAsync = false , title, ...rest } : IAppRoute ) => {
85- useA11yRouteChange ( isAsync ) ;
86+ const RouteWithTitleUpdates = ( { component : Component , title, ...rest } : IAppRoute ) => {
87+ useA11yRouteChange ( ) ;
8688 useDocumentTitle ( title ) ;
8789
8890 function routeWithTitle ( routeProps : RouteComponentProps ) {
8991 return < Component { ...rest } { ...routeProps } /> ;
9092 }
9193
92- return < Route render = { routeWithTitle } { ...rest } /> ;
94+ return < Route render = { routeWithTitle } { ...rest } /> ;
9395} ;
9496
9597const PageNotFound = ( { title } : { title : string } ) => {
@@ -105,15 +107,8 @@ const flattenedRoutes: IAppRoute[] = routes.reduce(
105107const AppRoutes = ( ) : React . ReactElement => (
106108 < LastLocationProvider >
107109 < Switch >
108- { flattenedRoutes . map ( ( { path, exact, component, title, isAsync } , idx ) => (
109- < RouteWithTitleUpdates
110- path = { path }
111- exact = { exact }
112- component = { component }
113- key = { idx }
114- title = { title }
115- isAsync = { isAsync }
116- />
110+ { flattenedRoutes . map ( ( { path, exact, component, title } , idx ) => (
111+ < RouteWithTitleUpdates path = { path } exact = { exact } component = { component } key = { idx } title = { title } />
117112 ) ) }
118113 < PageNotFound title = "404 Page Not Found" />
119114 </ Switch >
0 commit comments