Skip to content

Commit 8a9c73f

Browse files
committed
Helpers: AuthorizedRouter configurations updated and applied in routing
1 parent 8dab194 commit 8a9c73f

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

src/App/Components/Examples/ExampleComponent.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React, { FC } from "react";
22

3-
import { Route, Switch, Link } from "react-router-dom";
3+
import { Switch, Link } from "react-router-dom";
44

55
import Loadable from "../../../helpers/Loadable";
66
import ProtectedRouter from "../../../helpers/ProtectedRouter";
7+
import AuthorizedRouter from "../../../helpers/AuthorizedRouter";
78

89
import ROUTER from "../../../consts/routers";
910

@@ -51,7 +52,12 @@ const ExampleComponent: FC = () => {
5152
<ProtectedRouter user={user} path={ROUTER.POST}>
5253
<Post />
5354
</ProtectedRouter>
54-
<Route path={ROUTER.LOGIN}>
55+
<AuthorizedRouter
56+
user={user}
57+
path={ROUTER.LOGIN}
58+
dashboardPath={ROUTER.DASHBOARD}
59+
exact
60+
>
5561
<div>
5662
<h1>Login</h1>
5763
<br />
@@ -60,17 +66,21 @@ const ExampleComponent: FC = () => {
6066
<Link to={ROUTER.REGISTER}>Register</Link>
6167
</p>
6268
</div>
63-
</Route>
64-
<Route path={ROUTER.REGISTER}>
69+
</AuthorizedRouter>
70+
<AuthorizedRouter
71+
user={user}
72+
path={ROUTER.REGISTER}
73+
dashboardPath={ROUTER.DASHBOARD}
74+
>
6575
<div>
6676
<h1>Register</h1>
6777
<br />
6878
<p>
6979
Already a member?{" "}
70-
<Link to={ROUTER.LOGIN}>Register</Link>
80+
<Link to={ROUTER.LOGIN}>Login</Link>
7181
</p>
7282
</div>
73-
</Route>
83+
</AuthorizedRouter>
7484
</Switch>
7585
</div>
7686
);

src/helpers/AuthorizedRouter.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import ROUTER from "../consts/routers";
66
export interface Props {
77
children: ReactElement;
88
user: Record<string, unknown> | null;
9+
path: string;
910
dashboardPath?: string;
1011
[name: string]: unknown; // Accepts any number of object property; key will be string and value will be any
1112
}
@@ -39,12 +40,12 @@ export default AuthorizedRouter;
3940

4041
// Use
4142

42-
// <ProtectedRouter user={user} path={ROUTER.COUNT} exact loginPath='/login'>
43-
// <Count />
44-
// </ProtectedRouter>;
45-
// <ProtectedRouter user={user} path={ROUTER.COUNT} exact>
46-
// <Count />
47-
// </ProtectedRouter>;
48-
// <ProtectedRouter user={user} path={ROUTER.COUNT}>
49-
// <Count />
50-
// </ProtectedRouter>;
43+
// <AuthorizedRouter user={user} path="/login" exact dashboardPath='/'>
44+
// <Login />
45+
// </AuthorizedRouter>;
46+
// <AuthorizedRouter user={user} path="/login" exact>
47+
// <Login />
48+
// </AuthorizedRouter>;
49+
// <AuthorizedRouter user={user} path="/login">
50+
// <Login />
51+
// </AuthorizedRouter>;

src/helpers/ProtectedRouter.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { Route, Redirect } from "react-router-dom";
44
import ROUTER from "../consts/routers";
55

66
export interface Props {
7+
children: ReactElement;
78
user: Record<string, unknown> | null;
9+
path: string;
810
loginPath?: string;
9-
children: ReactElement;
1011
[name: string]: unknown; // Accepts any number of object property; key will be string and value will be any
1112
}
1213

@@ -15,9 +16,9 @@ export interface Props {
1516
* Helper component for redirecting unauthorized user
1617
*/
1718
const ProtectedRouter: FC<Props> = ({
19+
children,
1820
user,
1921
loginPath = ROUTER.LOGIN,
20-
children,
2122
...rest
2223
}: Props) => {
2324
const res = () => {

0 commit comments

Comments
 (0)