@@ -5,10 +5,11 @@ import {
5
5
BrowserRouter as Router ,
6
6
Route ,
7
7
Link ,
8
- Routes ,
9
- useParams ,
10
- useMatch ,
11
- Navigate
8
+ useLocation ,
9
+ matchPath ,
10
+ Switch ,
11
+ Redirect ,
12
+ useParams
12
13
} from "react-router-dom" ;
13
14
import { H5 , P } from "../Typography" ;
14
15
import Box from "../Box" ;
@@ -62,48 +63,46 @@ const PageCard = ({ children }) => {
62
63
} ;
63
64
64
65
const SideBarWithConfig = ( ) => {
65
- const isHome = useMatch ( "/" ) ;
66
- const isProfile = useMatch ( "/profile" ) ;
67
- const isSearch = useMatch ( "/search" ) ;
66
+ const location = useLocation ( ) ;
68
67
69
68
const items = [
70
69
{
71
70
iconName : "building" ,
72
71
name : "Home" ,
73
72
component : makeLinkComponent ( "/" ) ,
74
73
actionType : "link" ,
75
- isActive : ! ! isHome
74
+ isActive : matchPath ( location . pathname , { path : "/" , exact : true } )
76
75
} ,
77
76
{
78
77
iconName : "user" ,
79
78
name : "My profile" ,
80
79
component : makeLinkComponent ( "/profile" ) ,
81
80
actionType : "link" ,
82
- isActive : ! ! isProfile
81
+ isActive : matchPath ( location . pathname , { path : "/profile" } )
83
82
} ,
84
83
{
85
84
iconName : "id-card" ,
86
85
name : "Search Page" ,
87
86
component : makeLinkComponent ( "/search" ) ,
88
87
actionType : "link" ,
89
- isActive : isSearch
88
+ isActive : matchPath ( location . pathname , { path : "/search" } )
90
89
} ,
91
90
{
92
91
iconName : "snowflake" ,
93
92
name : "Filter" ,
94
- hide : ! isSearch , // Specify hide if you want to hide this item
93
+ hide : ! matchPath ( location . pathname , { path : "/search" } ) , // Specify hide if you want to hide this item
95
94
component : makePanelComponent ( "Filter" ) ,
96
95
actionType : "component" , // Use 'component' for a component
97
- pageSpecific : isSearch ,
96
+ pageSpecific : matchPath ( location . pathname , { path : "/search" } ) ,
98
97
isExpandedByDefault : true
99
98
} ,
100
99
{
101
100
iconName : "sun" ,
102
101
name : "People" ,
103
- hide : ! isProfile , // Specify hide if you want to hide this item
102
+ hide : ! matchPath ( location . pathname , { path : "/profile" } ) , // Specify hide if you want to hide this item
104
103
component : makePanelComponent ( "People" ) ,
105
104
actionType : "component" , // Use 'component' for a component
106
- pageSpecific : isProfile ,
105
+ pageSpecific : matchPath ( location . pathname , { path : "/profile" } ) ,
107
106
isExpandedByDefault : true
108
107
} ,
109
108
{
@@ -166,34 +165,24 @@ const SideBarWithConfig = () => {
166
165
return (
167
166
< Flex >
168
167
< SideNav items = { items } sideNavHeight = "500px" />
169
- < Routes >
170
- < Route
171
- path = "/"
172
- element = {
173
- < PageCard >
174
- < div > Home</ div >
175
- </ PageCard >
176
- }
177
- />
178
- < Route
179
- path = "/profile"
180
- element = {
181
- < PageCard >
182
- < div > Profile route</ div >
183
- </ PageCard >
184
- }
185
- />
186
- < Route
187
- path = "/teams/:teamId"
188
- element = {
189
- < PageCard >
190
- < Teams />
191
- </ PageCard >
192
- }
193
- />
194
-
195
- < Route path = "/iframe.html" element = { < Navigate to = "/" replace /> } />
196
- </ Routes >
168
+ < Switch >
169
+ < Route exact path = "/" >
170
+ < PageCard >
171
+ < div > Home</ div >
172
+ </ PageCard >
173
+ </ Route >
174
+ < Route path = "/profile" >
175
+ < PageCard >
176
+ < div > Profile route</ div >
177
+ </ PageCard >
178
+ </ Route >
179
+ < Route path = "/teams/:teamId" >
180
+ < PageCard >
181
+ < Teams />
182
+ </ PageCard >
183
+ </ Route >
184
+ < Redirect from = "/iframe.html" to = "/" />
185
+ </ Switch >
197
186
</ Flex >
198
187
) ;
199
188
} ;
0 commit comments