File tree Expand file tree Collapse file tree 3 files changed +29
-17
lines changed
Expand file tree Collapse file tree 3 files changed +29
-17
lines changed Original file line number Diff line number Diff line change 11import React , { FC } from "react" ;
22
3- import { Route , Switch , Link } from "react-router-dom" ;
3+ import { Switch , Link } from "react-router-dom" ;
44
55import Loadable from "../../../helpers/Loadable" ;
66import ProtectedRouter from "../../../helpers/ProtectedRouter" ;
7+ import AuthorizedRouter from "../../../helpers/AuthorizedRouter" ;
78
89import 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 ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import ROUTER from "../consts/routers";
66export 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 >;
Original file line number Diff line number Diff line change @@ -4,9 +4,10 @@ import { Route, Redirect } from "react-router-dom";
44import ROUTER from "../consts/routers" ;
55
66export 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 */
1718const ProtectedRouter : FC < Props > = ( {
19+ children,
1820 user,
1921 loginPath = ROUTER . LOGIN ,
20- children,
2122 ...rest
2223} : Props ) => {
2324 const res = ( ) => {
You can’t perform that action at this time.
0 commit comments