Skip to content

Commit

Permalink
Improve navbar rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Droniu committed Jul 16, 2024
1 parent 2ea2927 commit a43eed6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Box, ConfigurationIcon, HomeIcon, OrdersIcon, SellsIcon } from "@saleor
import { NavigationTile } from "./NavigationTile";

export const ROUTES = {
dashboard: "/app/",
dashboard: "/app",
checkout: "/app/checkout",
transactions: "/app/transactions",
configuration: "/app/configuration",
Expand Down
17 changes: 16 additions & 1 deletion src/components/NavigationTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,26 @@ interface NavigationTileProps {
children: React.ReactNode;
}

const navbarPathMatch = (href: string, pathname: string) => {
if (pathname === href) {
return true;
}

// pathname matches href + /[any param]
const regex = new RegExp(`^${href}/\\[.+\\]$`);
if (regex.test(pathname)) {
return true;
}

return false;
};

export const NavigationTile = ({ href, children }: NavigationTileProps) => {
const router = useRouter();
const { pathname } = router;

const isActive = pathname === href;
const isActive = navbarPathMatch(href, pathname);

return (
<Link href={href}>
<Text
Expand Down

0 comments on commit a43eed6

Please sign in to comment.