Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dashboard
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
red-giant
dashboard
Commits
64459540
Verified
Commit
64459540
authored
3 years ago
by
Defendi Alberto
Browse files
Options
Downloads
Patches
Plain Diff
Private route component
parent
40380a73
No related branches found
No related tags found
1 merge request
!23
Private route
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/App.tsx
+2
-1
2 additions, 1 deletion
src/App.tsx
src/components/utils/PrivateRoute/PrivateRoute.tsx
+38
-0
38 additions, 0 deletions
src/components/utils/PrivateRoute/PrivateRoute.tsx
with
40 additions
and
1 deletion
src/App.tsx
+
2
−
1
View file @
64459540
...
@@ -3,6 +3,7 @@ import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
...
@@ -3,6 +3,7 @@ import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import
{
HomePage
}
from
'
components/HomePage/HomePage
'
;
import
{
HomePage
}
from
'
components/HomePage/HomePage
'
;
import
{
AuthUser
}
from
'
components/AuthUser/AuthUser
'
;
import
{
AuthUser
}
from
'
components/AuthUser/AuthUser
'
;
import
{
LandingPage
}
from
'
components/LandingPage/LandingPage
'
;
import
{
LandingPage
}
from
'
components/LandingPage/LandingPage
'
;
import
{
PrivateRoute
}
from
'
components/utils/PrivateRoute/PrivateRoute
'
;
export
const
App
:
FC
=
()
=>
(
export
const
App
:
FC
=
()
=>
(
<
Router
>
<
Router
>
...
@@ -10,7 +11,7 @@ export const App: FC = () => (
...
@@ -10,7 +11,7 @@ export const App: FC = () => (
<
Switch
>
<
Switch
>
<
Route
path
=
"/auth"
component
=
{
AuthUser
}
/>
<
Route
path
=
"/auth"
component
=
{
AuthUser
}
/>
<
Route
exact
path
=
"/"
component
=
{
LandingPage
}
/>
<
Route
exact
path
=
"/"
component
=
{
LandingPage
}
/>
<
Route
exact
path
=
"/home"
c
omponent
=
{
HomePage
}
/>
<
PrivateRoute
path
=
"/home"
C
omponent
=
{
HomePage
}
/>
</
Switch
>
</
Switch
>
</
div
>
</
div
>
</
Router
>
</
Router
>
...
...
This diff is collapsed.
Click to expand it.
src/components/utils/PrivateRoute/PrivateRoute.tsx
0 → 100644
+
38
−
0
View file @
64459540
import
React
from
'
react
'
;
import
{
Route
,
Redirect
,
RouteProps
}
from
'
react-router-dom
'
;
/**
* A wrapper for <Route> that redirects to the login screen if you're not yet authenticated.
* */
type
Props
=
{
Component
:
React
.
FC
<
RouteProps
>
;
path
:
string
;
};
/* eslint-disable react/jsx-props-no-spreading */
export
const
PrivateRoute
=
({
Component
,
path
}:
Props
):
JSX
.
Element
=>
{
const
isAuthed
=
false
;
const
message
=
'
Please log in to view this page
'
;
return
(
<
Route
exact
=
{
false
}
path
=
{
path
}
render
=
{
(
props
:
RouteProps
)
=>
isAuthed
?
(
<
Component
{
...
props
}
/>
)
:
(
<
Redirect
to
=
{
{
pathname
:
'
/auth
'
,
state
:
{
message
,
requestedPath
:
path
,
},
}
}
/>
)
}
/>
);
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment