@@ -4,6 +4,8 @@ import { Alert, PageSection } from '@patternfly/react-core';
44import { DynamicImport } from '@app/DynamicImport' ;
55import { accessibleRouteChangeHandler } from '@app/utils/utils' ;
66import { Dashboard } from '@app/Dashboard/Dashboard' ;
7+ import { GeneralSettings } from '@app/Settings/General/GeneralSettings' ;
8+ import { ProfileSettings } from '@app/Settings/Profile/ProfileSettings' ;
79import { NotFound } from '@app/NotFound/NotFound' ;
810import { useDocumentTitle } from '@app/utils/useDocumentTitle' ;
911import { LastLocationProvider , useLastLocation } from 'react-router-last-location' ;
@@ -38,17 +40,25 @@ const Support = (routeProps: RouteComponentProps): React.ReactElement => {
3840} ;
3941
4042export interface IAppRoute {
41- label ?: string ;
43+ label ?: string ; // Excluding the label will exclude the route from the nav sidebar in AppLayout
4244 /* eslint-disable @typescript-eslint/no-explicit-any */
4345 component : React . ComponentType < RouteComponentProps < any > > | React . ComponentType < any > ;
4446 /* eslint-enable @typescript-eslint/no-explicit-any */
4547 exact ?: boolean ;
4648 path : string ;
4749 title : string ;
4850 isAsync ?: boolean ;
51+ routes ?: undefined ;
4952}
5053
51- const routes : IAppRoute [ ] = [
54+ export interface IAppRouteGroup {
55+ label : string ;
56+ routes : IAppRoute [ ] ;
57+ }
58+
59+ export type AppRouteConfig = IAppRoute | IAppRouteGroup ;
60+
61+ const routes : AppRouteConfig [ ] = [
5262 {
5363 component : Dashboard ,
5464 exact : true ,
@@ -64,6 +74,25 @@ const routes: IAppRoute[] = [
6474 path : '/support' ,
6575 title : 'PatternFly Seed | Support Page' ,
6676 } ,
77+ {
78+ label : 'Settings' ,
79+ routes : [
80+ {
81+ component : GeneralSettings ,
82+ exact : true ,
83+ label : 'General' ,
84+ path : '/settings/general' ,
85+ title : 'PatternFly Seed | General Settings' ,
86+ } ,
87+ {
88+ component : ProfileSettings ,
89+ exact : true ,
90+ label : 'Profile' ,
91+ path : '/settings/profile' ,
92+ title : 'PatternFly Seed | Profile Settings' ,
93+ } ,
94+ ] ,
95+ } ,
6796] ;
6897
6998// a custom hook for sending focus to the primary content container
@@ -97,10 +126,15 @@ const PageNotFound = ({ title }: { title: string }) => {
97126 return < Route component = { NotFound } /> ;
98127} ;
99128
129+ const flattenedRoutes : IAppRoute [ ] = routes . reduce (
130+ ( flattened , route ) => [ ...flattened , ...( route . routes ? route . routes : [ route ] ) ] ,
131+ [ ] as IAppRoute [ ]
132+ ) ;
133+
100134const AppRoutes = ( ) : React . ReactElement => (
101135 < LastLocationProvider >
102136 < Switch >
103- { routes . map ( ( { path, exact, component, title, isAsync } , idx ) => (
137+ { flattenedRoutes . map ( ( { path, exact, component, title, isAsync } , idx ) => (
104138 < RouteWithTitleUpdates
105139 path = { path }
106140 exact = { exact }
0 commit comments