fix(dashboard): settings navigation loop (#7412)
* fix: settings navigation loop * fix comment
This commit is contained in:
1 parent
6f1b90f207
commit
ccf335fcf4
1 file changed
+13
-1
+13
-1
@@ -80,6 +80,18 @@ const useDeveloperRoutes = (): NavItemProps[] => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure that the `from` prop is not another settings route, to avoid
|
||||||
|
* the user getting stuck in a navigation loop.
|
||||||
|
*/
|
||||||
|
const getSafeFromValue = (from: string) => {
|
||||||
|
if (from.startsWith("/settings")) {
|
||||||
|
return "/orders"
|
||||||
|
}
|
||||||
|
|
||||||
|
return from
|
||||||
|
}
|
||||||
|
|
||||||
const SettingsSidebar = () => {
|
const SettingsSidebar = () => {
|
||||||
const routes = useSettingRoutes()
|
const routes = useSettingRoutes()
|
||||||
const developerRoutes = useDeveloperRoutes()
|
const developerRoutes = useDeveloperRoutes()
|
||||||
@@ -90,7 +102,7 @@ const SettingsSidebar = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (location.state?.from) {
|
if (location.state?.from) {
|
||||||
setFrom(location.state.from)
|
setFrom(getSafeFromValue(location.state.from))
|
||||||
}
|
}
|
||||||
}, [location])
|
}, [location])
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user