Skip to content

Commit

Permalink
update findSlug logic to use fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Sep 30, 2024
1 parent dbff51c commit f334814
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Common/hooks/useSlug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const useSlugs = (...prefix: string[]) => {
const findSlug = (segments: string[], prefix: string, fallback?: string) => {
const index = segments.findIndex((segment) => segment === prefix);
if (index === -1) {
if (fallback) {
return fallback;
}
throw new Error(
`Prefix "${prefix}" not found in path "${segments.join("/")}"`,
);
Expand Down

0 comments on commit f334814

Please sign in to comment.