Skip to content

Commit 77815c5

Browse files
Revert/react router dom to v5 (#337)
* revert react-router-dom to v5 * update version
1 parent e9f90dc commit 77815c5

File tree

4 files changed

+127
-88
lines changed

4 files changed

+127
-88
lines changed

lib/components/SideNav/SideNav.stories.js

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import {
55
BrowserRouter as Router,
66
Route,
77
Link,
8-
Routes,
9-
useParams,
10-
useMatch,
11-
Navigate
8+
useLocation,
9+
matchPath,
10+
Switch,
11+
Redirect,
12+
useParams
1213
} from "react-router-dom";
1314
import { H5, P } from "../Typography";
1415
import Box from "../Box";
@@ -62,48 +63,46 @@ const PageCard = ({ children }) => {
6263
};
6364

6465
const SideBarWithConfig = () => {
65-
const isHome = useMatch("/");
66-
const isProfile = useMatch("/profile");
67-
const isSearch = useMatch("/search");
66+
const location = useLocation();
6867

6968
const items = [
7069
{
7170
iconName: "building",
7271
name: "Home",
7372
component: makeLinkComponent("/"),
7473
actionType: "link",
75-
isActive: !!isHome
74+
isActive: matchPath(location.pathname, { path: "/", exact: true })
7675
},
7776
{
7877
iconName: "user",
7978
name: "My profile",
8079
component: makeLinkComponent("/profile"),
8180
actionType: "link",
82-
isActive: !!isProfile
81+
isActive: matchPath(location.pathname, { path: "/profile" })
8382
},
8483
{
8584
iconName: "id-card",
8685
name: "Search Page",
8786
component: makeLinkComponent("/search"),
8887
actionType: "link",
89-
isActive: isSearch
88+
isActive: matchPath(location.pathname, { path: "/search" })
9089
},
9190
{
9291
iconName: "snowflake",
9392
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
9594
component: makePanelComponent("Filter"),
9695
actionType: "component", // Use 'component' for a component
97-
pageSpecific: isSearch,
96+
pageSpecific: matchPath(location.pathname, { path: "/search" }),
9897
isExpandedByDefault: true
9998
},
10099
{
101100
iconName: "sun",
102101
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
104103
component: makePanelComponent("People"),
105104
actionType: "component", // Use 'component' for a component
106-
pageSpecific: isProfile,
105+
pageSpecific: matchPath(location.pathname, { path: "/profile" }),
107106
isExpandedByDefault: true
108107
},
109108
{
@@ -166,34 +165,24 @@ const SideBarWithConfig = () => {
166165
return (
167166
<Flex>
168167
<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>
197186
</Flex>
198187
);
199188
};

lib/components/StyledLink/StyledLink.stories.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import StyledLink from ".";
33
import Box from "../Box";
44
import Flex from "../Flex";
55
import Spacer from "../Spacer";
6-
import { BrowserRouter, Route, Routes } from "react-router-dom";
6+
import { BrowserRouter, Route, Switch } from "react-router-dom";
77

88
export default {
99
title: "Components/StyledLink",
@@ -64,19 +64,13 @@ export const reactLink = () => (
6464
{route.label}
6565
</StyledLink>
6666
))}
67-
<Routes>
67+
<Switch>
6868
{routes.map((route) => (
69-
<Route
70-
key={route.path}
71-
path={route.path}
72-
element={
73-
<div style={{ padding: "100px" }}>
74-
ROUTE RENDERED: {route.label}
75-
</div>
76-
}
77-
/>
69+
<Route key={route.path} path={route.path} exact={route.exact}>
70+
<div style={{ padding: "100px" }}>ROUTE RENDERED: {route.label}</div>
71+
</Route>
7872
))}
79-
</Routes>
73+
</Switch>
8074
</BrowserRouter>
8175
);
8276
reactLink.storyName = "Using react-router-dom";

package-lock.json

Lines changed: 88 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "orcs-design-system",
3-
"version": "3.2.39",
3+
"version": "3.2.40",
44
"engines": {
55
"node": "20.12.2"
66
},
@@ -66,7 +66,7 @@
6666
"react-intersection-observer": "^9.4.3",
6767
"react-moment-proptypes": "^1.8.1",
6868
"react-number-format": "^5.3.0",
69-
"react-router-dom": "^6.26.2",
69+
"react-router-dom": "^5.3.4",
7070
"react-select": "^5.7.4",
7171
"styled-system": "^5.1.5"
7272
},

0 commit comments

Comments
 (0)