Router integration
Connect Glyph to your router once: links navigate client-side and navigation items mark the current page automatically.
Status: beta. Category: Patterns.
import { RouterLink } from '@glyphui/ui/react-router'
Exports: reactRouter, RouterLink, useRouterIsActive, matchPath, useRouterUrlAdapter.
Notes
- Pass it once: <GlyphProvider router={reactRouter}>. Sidebar, Navbar and NavigationMenu items then set aria-current="page" from the URL.
- Matching works like React Router’s NavLink: an item is active on its path and every path below it. Pass end on index items such as /app.
- An explicit active prop always wins, so you can still mark items yourself.
- Hash links, external URLs and mailto: render as plain anchors and are never marked active.
- Other routers: pass { Link, useIsActive } yourself. The getting-started guide has TanStack Router and Next.js versions.
- Requires react-router 7 or later as a peer dependency.
- useRouterUrlAdapter() connects DataTable’s useTableUrlState to React Router: useTableUrlState({ adapter: useRouterUrlAdapter() }), so the router’s location and useSearchParams always match the table.
Example: Automatic active items
These items use the docs’ own router: the current page is marked without an active prop.
import { AppShell, Sidebar, SidebarContent, SidebarItem, SidebarSection, Text } from '@glyphui/ui'
import { BookOpen, LayoutGrid, PanelLeft, Route } from 'lucide-react'
export default function Example() {
return (
<div className="h-72 overflow-hidden rounded-lg border border-border">
<AppShell
layout="embedded"
sidebar={
<Sidebar>
<SidebarContent>
<SidebarSection label="Docs">
<SidebarItem href="/components" end icon={<LayoutGrid />}>
All components
</SidebarItem>
<SidebarItem href="/components/router" icon={<Route />}>
Router integration
</SidebarItem>
<SidebarItem href="/components/sidebar" icon={<PanelLeft />}>
Sidebar
</SidebarItem>
<SidebarItem href="/getting-started" icon={<BookOpen />}>
Getting started
</SidebarItem>
</SidebarSection>
</SidebarContent>
</Sidebar>
}
>
<div className="p-5">
<Text tone="muted">
No item sets active. “Router integration” is highlighted because it matches this page.
</Text>
</div>
</AppShell>
</div>
)
}
Live page: https://glyphui.xyz/components/router