update to use segments

This commit is contained in:
Rami Bitar
2026-06-06 10:19:56 -04:00
parent 64610e997d
commit 0625487af0
3 changed files with 8 additions and 8 deletions

View File

@@ -11,8 +11,8 @@ export type ResolvedRoute = {
params: Record<string, string>;
};
const resolveRoute = (slug: string[] = []): ResolvedRoute => {
const path = slug.length === 0 ? "/" : `/${slug.join("/")}`;
const resolveRoute = (segments: string[] = []): ResolvedRoute => {
const path = segments.length === 0 ? "/" : `/${segments.join("/")}`;
for (const { key, prefix, param } of TEMPLATE_PATTERNS) {
if (path.startsWith(prefix) && path.length > prefix.length) {
@@ -30,8 +30,8 @@ const resolveRoute = (slug: string[] = []): ResolvedRoute => {
*/
export const useRouteHandle = (): string | undefined => {
const params = useParams();
const slug = Array.isArray(params?.slug) ? (params.slug as string[]) : [];
return resolveRoute(slug).params.handle;
const segments = Array.isArray(params?.slug) ? (params.slug as string[]) : [];
return resolveRoute(segments).params.handle;
};
export default resolveRoute;