Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/loud-tomatoes-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Exclude external custom links from route matching. Previously adding external links to custom pages would cause all pages that are defined below it to throw an error.
25 changes: 11 additions & 14 deletions packages/clerk-js/src/ui/elements/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContextAndHook } from '@clerk/shared/react';
import React, { useEffect } from 'react';
import React, { useCallback } from 'react';

import type { LocalizationKey } from '../customizables';
import { Button, Col, descriptors, Flex, Heading, Icon, Text, useLocalizations } from '../customizables';
Expand Down Expand Up @@ -33,7 +33,6 @@ export type NavbarRoute = {
path: string;
external?: boolean;
};
type RouteId = NavbarRoute['id'];
type NavBarProps = {
title: LocalizationKey;
description: LocalizationKey;
Expand All @@ -44,7 +43,6 @@ type NavBarProps = {

export const NavBar = (props: NavBarProps) => {
const { contentRef, title, description, routes, header } = props;
const [activeId, setActiveId] = React.useState<RouteId>('');
const { close } = useNavbarContext();
const { navigate } = useRouter();
const { navigateToFlowStart } = useNavigateToFlowStart();
Expand All @@ -61,7 +59,6 @@ export const NavBar = (props: NavBarProps) => {

const navigateToInternalRoute = async (route: NavbarRoute) => {
if (contentRef.current) {
setActiveId(route.id);
close();
if (route.path === '/') {
// TODO: this is needed to correctly handle navigations
Expand All @@ -73,17 +70,17 @@ export const NavBar = (props: NavBarProps) => {
}
};

useEffect(() => {
routes.every(route => {
const isRoot = router.currentPath === router.fullPath && route.path === '/';
const matchesPath = router.matches(route.path);
if (isRoot || matchesPath) {
setActiveId(route.id);
const checkIfActive = useCallback(
(a: NavbarRoute) => {
if (a.external) {
return false;
}
return true;
});
}, [router.currentPath]);
const isRoot = router.currentPath === router.fullPath && a.path === '/';
const matchesPath = router.matches(a.path);
return isRoot || matchesPath;
},
[router.currentPath],
);

const items = (
<Col
Expand All @@ -99,7 +96,7 @@ export const NavBar = (props: NavBarProps) => {
iconElementId={descriptors.navbarButtonIcon.setId(r.id) as any}
onClick={handleNavigate(r)}
icon={r.icon}
isActive={activeId === r.id}
isActive={checkIfActive(r)}
sx={t => ({
padding: `${t.space.$1x5} ${t.space.$3}`,
})}
Expand Down