Skip to content

Commit 7a25732

Browse files
use react-router v6
1 parent 7a2c6d1 commit 7a25732

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

custom-login/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
"version": "0.2.0",
44
"private": true,
55
"dependencies": {
6-
"@okta/okta-react": "^3.0.8",
6+
"@okta/okta-react": "github:okta/okta-react#OKTA-318565-react-router-6",
77
"@okta/okta-signin-widget": "^4.5.0",
88
"colors": "^1.1.2",
99
"cross-env": "^5.1.3",
1010
"dotenv": "^8.1.0",
1111
"jquery": "^3.4.1",
1212
"react": "^16.8.0",
1313
"react-dom": "^16.8.0",
14-
"react-router-dom": "^5.0.0",
14+
"history": "^5.0.0",
15+
"react-router-dom": "^6.0.0-beta.0",
1516
"react-scripts": "^4.0.0",
1617
"semantic-ui-css": "^2.2.12",
1718
"semantic-ui-react": "^2.0.1",

custom-login/src/App.jsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import React from 'react';
14-
import { BrowserRouter as Router, Route, useHistory } from 'react-router-dom';
14+
import { BrowserRouter as Router, Route, Routes, useNavigate } from 'react-router-dom';
1515
import { Security, SecureRoute, LoginCallback } from '@okta/okta-react';
1616
import { Container } from 'semantic-ui-react';
1717
import config from './config';
@@ -22,11 +22,11 @@ import Navbar from './Navbar';
2222
import Profile from './Profile';
2323

2424
const HasAccessToRouter = () => {
25-
const history = useHistory(); // example from react-router
25+
const navigate = useNavigate(); // example from react-router
2626

2727
const customAuthHandler = () => {
2828
// Redirect to the /login page that has a CustomLoginComponent
29-
history.push('/login');
29+
navigate('/login');
3030
};
3131

3232
return (
@@ -36,11 +36,13 @@ const HasAccessToRouter = () => {
3636
>
3737
<Navbar />
3838
<Container text style={{ marginTop: '7em' }}>
39-
<Route path="/" exact component={Home} />
40-
<Route path="/login/callback" component={LoginCallback} />
41-
<Route path="/login" component={CustomLoginComponent} />
42-
<SecureRoute path="/messages" component={Messages} />
43-
<SecureRoute path="/profile" component={Profile} />
39+
<Routes>
40+
<Route path="/" element={<Home />} />
41+
<Route path="/login/callback" element={<LoginCallback />} />
42+
<Route path="/login" element={<CustomLoginComponent />} />
43+
<SecureRoute path="/profile/*" element={<Profile />} />
44+
<SecureRoute path="/messages/*" element={<Messages />} />
45+
</Routes>
4446
</Container>
4547
</Security>
4648
);

okta-hosted-login/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
"version": "0.2.0",
44
"private": true,
55
"dependencies": {
6-
"@okta/okta-react": "^3.0.7",
6+
"@okta/okta-react": "github:okta/okta-react#OKTA-318565-react-router-6",
77
"colors": "^1.4.0",
88
"cross-env": "^7.0.2",
99
"dotenv": "^8.2.0",
1010
"react": "^16.13.1",
1111
"react-dom": "^16.13.1",
12-
"react-router-dom": "^5.2.0",
12+
"history": "^5.0.0",
13+
"react-router-dom": "^6.0.0-beta.0",
1314
"react-scripts": "^4.0.0",
1415
"semantic-ui-css": "^2.4.1",
1516
"semantic-ui-react": "^1.2.1",

okta-hosted-login/src/App.jsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import React from 'react';
14-
import { BrowserRouter as Router, Route } from 'react-router-dom';
14+
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
1515
import { Security, SecureRoute, LoginCallback } from '@okta/okta-react';
1616
import { Container } from 'semantic-ui-react';
1717
import config from './config';
@@ -25,10 +25,12 @@ const App = () => (
2525
<Security {...config.oidc}>
2626
<Navbar />
2727
<Container text style={{ marginTop: '7em' }}>
28-
<Route path="/" exact component={Home} />
29-
<Route path="/login/callback" component={LoginCallback} />
30-
<SecureRoute path="/messages" component={Messages} />
31-
<SecureRoute path="/profile" component={Profile} />
28+
<Routes>
29+
<Route path="/" element={<Home />} />
30+
<Route path="/login/callback" element={<LoginCallback />} />
31+
<SecureRoute path="/profile/*" element={<Profile />} />
32+
<SecureRoute path="/messages/*" element={<Messages />} />
33+
</Routes>
3234
</Container>
3335
</Security>
3436
</Router>

0 commit comments

Comments
 (0)