0: Did not match union.
Expected type { link: string; } | { items: array; } | { autogenerate: object; } | { slug: string } | string
Received { "type": "link", "label": "Admin test", "href": "/admin/testowy", "isCurrent": false, "attrs": {} }
My partial index.astro:
const dynamicSidebar = generateSidebar(userRole);
<StarlightPage
frontmatter={frontmatter}
hasSidebar={true}
sidebar={dynamicSidebar}
my utils/sidebarUtils.ts
export function generateSidebar(userRole: string, currentPathname: string) {
const allSidebarItems = [
{
link: '/admin/testowy', // Bezpośredni link
label: 'Admin test',
},
];
const sidebar = allSidebarItems.map(item => ({
link: item.link,
label: item.label,
}));
return sidebar.map(item => ({
type: 'link',
label: item.label,
href: item.link,
isCurrent: false, // Możesz tu dostosować logikę, by sprawdzić, czy jest to obecny link
badge: undefined,
attrs: {}
}));
}
My components/DynamicSidebar.astro
import type { Props } from '<@&1055234544183287879>/starlight/props';
import Default from '@astrojs/starlight/components/Sidebar.astro';
import { generateSidebar } from '../utils/sidebarUtils';
const { props } = Astro;
const userRole = Astro.locals.user?.role || Astro.cookies.get('userRole')?.value || 'klient';
const currentPathname = Astro.url.pathname;
console.log('DynamicSidebar: userRole:', userRole);
const dynamicSidebar = generateSidebar(userRole) || [];
<Default {...props} sidebar={dynamicSidebar} />