-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a47f616
commit 8e0b29e
Showing
3 changed files
with
60 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useContext } from 'react'; | ||
import { Route, Redirect } from 'react-router-dom'; | ||
import { AuthContext } from 'contexts/auth'; | ||
|
||
const PrivateRoute: React.FC<any> = ({ | ||
component: RouteComponent, | ||
...rest | ||
}) => { | ||
const { currentUser } = useContext(AuthContext); | ||
|
||
return ( | ||
<Route | ||
{...rest} | ||
render={(routeProps) => | ||
currentUser ? <RouteComponent {...routeProps} /> : <Redirect to="/" /> | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
export default PrivateRoute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { IonRouterOutlet } from '@ionic/react'; | ||
import { AuthContext } from 'contexts/auth'; | ||
import { useContext } from 'react'; | ||
import { Redirect, Route } from 'react-router-dom'; | ||
import PrivateRoute from './PrivateRoute'; | ||
|
||
import Home from 'pages/Home'; | ||
import About from 'pages/About'; | ||
import Login from 'pages/auth/Login'; | ||
import Register from 'pages/auth/Register'; | ||
import EditProfile from 'pages/main/profile/EditProfile'; | ||
|
||
import MainTabs from 'components/MainTabs'; | ||
|
||
const Routes: React.FC = () => { | ||
const { currentUser } = useContext(AuthContext); | ||
|
||
return ( | ||
<IonRouterOutlet id="main"> | ||
<Route exact path="/" component={Home} /> | ||
<Route path="/login" component={Login} /> | ||
<Route path="/register" component={Register} /> | ||
<Route path="/about" component={About} /> | ||
<PrivateRoute path="/main" component={MainTabs} /> | ||
<PrivateRoute path="/edit-profile" component={EditProfile} /> | ||
|
||
{currentUser ? ( | ||
<Redirect exact from="/" to="/main" /> | ||
) : ( | ||
<Redirect to="/" /> | ||
)} | ||
</IonRouterOutlet> | ||
); | ||
}; | ||
|
||
export default Routes; |