Fix "main route" detection
There was a possibility that routes were incorrectly detected as main routes which caused the back button to not get shown. E.g. a route that is only visible on desktop was still considered a main route on mobile devices
This commit is contained in:
@@ -82,11 +82,7 @@ export function DefaultNavBar() {
|
|||||||
const getOptionForDirection = useGetOptionForDirection();
|
const getOptionForDirection = useGetOptionForDirection();
|
||||||
const { pathname } = useLocation();
|
const { pathname } = useLocation();
|
||||||
const handleBack = useBackButton();
|
const handleBack = useBackButton();
|
||||||
|
|
||||||
const isMobileWidth = MediaQuery.useIsMobileWidth();
|
const isMobileWidth = MediaQuery.useIsMobileWidth();
|
||||||
const isMainRoute = navbarItems.some(({ path }) => path === pathname);
|
|
||||||
|
|
||||||
const actualNavBarWidth = isMobileWidth || isCollapsed ? 0 : navBarWidth;
|
|
||||||
|
|
||||||
const appBarRef = useRef<HTMLDivElement | null>(null);
|
const appBarRef = useRef<HTMLDivElement | null>(null);
|
||||||
useResizeObserver(
|
useResizeObserver(
|
||||||
@@ -103,6 +99,19 @@ export function DefaultNavBar() {
|
|||||||
return () => setAppBarHeight(0);
|
return () => setAppBarHeight(0);
|
||||||
}, [override.status]);
|
}, [override.status]);
|
||||||
|
|
||||||
|
const isMainRoute = navbarItems.some(({ path, show }) => {
|
||||||
|
if (isMobileWidth && show === 'desktop') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isMobileWidth && show === 'mobile') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path === pathname;
|
||||||
|
});
|
||||||
|
const actualNavBarWidth = isMobileWidth || isCollapsed ? 0 : navBarWidth;
|
||||||
|
|
||||||
const activeNavBar: NavbarItem['show'] = isMobileWidth ? 'mobile' : 'desktop';
|
const activeNavBar: NavbarItem['show'] = isMobileWidth ? 'mobile' : 'desktop';
|
||||||
const visibleNavBarItems = useMemo(
|
const visibleNavBarItems = useMemo(
|
||||||
() => navbarItems.filter(({ show }) => ['both', activeNavBar].includes(show)),
|
() => navbarItems.filter(({ show }) => ['both', activeNavBar].includes(show)),
|
||||||
@@ -110,6 +119,11 @@ export function DefaultNavBar() {
|
|||||||
);
|
);
|
||||||
const NavBarComponent = useMemo(() => (isMobileWidth ? MobileBottomBar : DesktopSideBar), [isMobileWidth]);
|
const NavBarComponent = useMemo(() => (isMobileWidth ? MobileBottomBar : DesktopSideBar), [isMobileWidth]);
|
||||||
|
|
||||||
|
const navBar = useMemo(
|
||||||
|
() => <NavBarComponent navBarItems={visibleNavBarItems} />,
|
||||||
|
[NavBarComponent, visibleNavBarItems],
|
||||||
|
);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (!isMobileWidth) {
|
if (!isMobileWidth) {
|
||||||
// do not reset navbar width to prevent grid from jumping due to the changing grid item width
|
// do not reset navbar width to prevent grid from jumping due to the changing grid item width
|
||||||
@@ -119,11 +133,6 @@ export function DefaultNavBar() {
|
|||||||
setNavBarWidth(0);
|
setNavBarWidth(0);
|
||||||
}, [isMobileWidth]);
|
}, [isMobileWidth]);
|
||||||
|
|
||||||
const navBar = useMemo(
|
|
||||||
() => <NavBarComponent navBarItems={visibleNavBarItems} />,
|
|
||||||
[NavBarComponent, visibleNavBarItems],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Allow default navbar to be overrided
|
// Allow default navbar to be overrided
|
||||||
if (override.status) return override.value;
|
if (override.status) return override.value;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user