Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
93e848d1
Commit
93e848d1
authored
May 28, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: tweak root redirector
parent
60b5b481
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
39 deletions
+24
-39
RootLayout.tsx
web/src/layouts/RootLayout.tsx
+21
-11
RootRedirector.tsx
web/src/pages/RootRedirector.tsx
+0
-20
index.tsx
web/src/router/index.tsx
+3
-8
No files found.
web/src/layouts/
Home
Layout.tsx
→
web/src/layouts/
Root
Layout.tsx
View file @
93e848d1
...
...
@@ -10,23 +10,33 @@ import useResponsiveWidth from "@/hooks/useResponsiveWidth";
import
Loading
from
"@/pages/Loading"
;
import
{
Routes
}
from
"@/router"
;
const
Home
Layout
=
()
=>
{
const
Root
Layout
=
()
=>
{
const
location
=
useLocation
();
const
{
sm
}
=
useResponsiveWidth
();
const
currentUser
=
useCurrentUser
();
const
[
lastVisited
]
=
useLocalStorage
<
string
>
(
"lastVisited"
,
"/home"
);
const
[
collapsed
,
setCollapsed
]
=
useLocalStorage
<
boolean
>
(
"navigation-collapsed"
,
false
);
const
[
initialized
,
setInitialized
]
=
useState
(
false
);
// Redirect to explore page if not logged in.
useEffect
(()
=>
{
if
(
!
currentUser
&&
([
Routes
.
HOME
,
Routes
.
TIMELINE
,
Routes
.
RESOURCES
,
Routes
.
INBOX
,
Routes
.
ARCHIVED
,
Routes
.
SETTING
]
as
string
[]).
includes
(
location
.
pathname
,
)
)
{
window
.
location
.
href
=
Routes
.
EXPLORE
;
return
;
if
(
!
currentUser
)
{
if
(
([
Routes
.
ROOT
,
Routes
.
HOME
,
Routes
.
TIMELINE
,
Routes
.
RESOURCES
,
Routes
.
INBOX
,
Routes
.
ARCHIVED
,
Routes
.
SETTING
]
as
string
[]).
includes
(
location
.
pathname
,
)
)
{
window
.
location
.
href
=
Routes
.
EXPLORE
;
return
;
}
}
else
{
if
(
location
.
pathname
===
Routes
.
ROOT
)
{
if
(
lastVisited
&&
([
Routes
.
HOME
,
Routes
.
TIMELINE
]
as
string
[]).
includes
(
lastVisited
))
{
window
.
location
.
href
=
lastVisited
;
}
else
{
window
.
location
.
href
=
Routes
.
HOME
;
}
return
;
}
}
setInitialized
(
true
);
...
...
@@ -75,4 +85,4 @@ const HomeLayout = () => {
);
};
export
default
Home
Layout
;
export
default
Root
Layout
;
web/src/pages/RootRedirector.tsx
deleted
100644 → 0
View file @
60b5b481
import
{
useEffect
}
from
"react"
;
import
useLocalStorage
from
"react-use/lib/useLocalStorage"
;
import
useNavigateTo
from
"@/hooks/useNavigateTo"
;
const
RootRedirector
:
React
.
FC
=
()
=>
{
const
[
lastVisited
]
=
useLocalStorage
<
string
>
(
"lastVisited"
,
"/home"
);
const
navigateTo
=
useNavigateTo
();
useEffect
(()
=>
{
if
(
lastVisited
===
"/home"
||
lastVisited
===
"/timeline"
)
{
navigateTo
(
lastVisited
);
}
else
{
navigateTo
(
"/home"
);
}
},
[]);
return
<></>;
};
export
default
RootRedirector
;
web/src/router/index.tsx
View file @
93e848d1
import
{
createBrowserRouter
}
from
"react-router-dom"
;
import
App
from
"@/App"
;
import
HomeLayout
from
"@/layouts/Home
Layout"
;
import
RootLayout
from
"@/layouts/Root
Layout"
;
import
SuspenseWrapper
from
"@/layouts/SuspenseWrapper"
;
import
About
from
"@/pages/About"
;
import
Archived
from
"@/pages/Archived"
;
...
...
@@ -12,7 +12,6 @@ import MemoDetail from "@/pages/MemoDetail";
import
NotFound
from
"@/pages/NotFound"
;
import
PermissionDenied
from
"@/pages/PermissionDenied"
;
import
Resources
from
"@/pages/Resources"
;
import
RootRedirector
from
"@/pages/RootRedirector"
;
import
Setting
from
"@/pages/Setting"
;
import
SignIn
from
"@/pages/SignIn"
;
import
SignUp
from
"@/pages/SignUp"
;
...
...
@@ -56,13 +55,9 @@ const router = createBrowserRouter([
],
},
{
path
:
"/"
,
element
:
<
Home
Layout
/>,
path
:
Routes
.
ROOT
,
element
:
<
Root
Layout
/>,
children
:
[
{
path
:
Routes
.
ROOT
,
element
:
<
RootRedirector
/>,
},
{
path
:
Routes
.
HOME
,
element
:
<
Home
/>,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment