Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: redirect only happening on root path with replace (#2981)
Adds a fix for overeager redirects, now we will redirect on the root path and replace on our redirects from login. Co-authored-by: Gastón Fournier <gaston@getunleash.ai>
- Loading branch information
1 parent
99f45b4
commit 38be01f
Showing
8 changed files
with
51 additions
and
70 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,39 @@ | ||
import { useCallback, useEffect, useContext } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import useProjects from '../hooks/api/getters/useProjects/useProjects'; | ||
import { useLastViewedProject } from '../hooks/useLastViewedProject'; | ||
import UIContext from 'contexts/UIContext'; | ||
import Loader from './common/Loader/Loader'; | ||
|
||
export const InitialRedirect = () => { | ||
const { lastViewed } = useLastViewedProject(); | ||
const { projects, loading } = useProjects(); | ||
const navigate = useNavigate(); | ||
|
||
// Redirect based on project and last viewed | ||
const getRedirect = useCallback(() => { | ||
if (projects && lastViewed) { | ||
return `/projects/${lastViewed}`; | ||
} | ||
|
||
if (projects && !lastViewed && projects.length === 1) { | ||
return `/projects/${projects[0].id}`; | ||
} | ||
|
||
return '/projects'; | ||
}, [lastViewed, projects]); | ||
|
||
const redirect = () => { | ||
navigate(getRedirect(), { replace: true }); | ||
}; | ||
|
||
useEffect(() => { | ||
redirect(); | ||
}, [getRedirect]); | ||
|
||
if (loading) { | ||
return <Loader />; | ||
} | ||
|
||
return null; | ||
}; |
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
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
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