Skip to content

adminHref

adminHref(target, basePath): string

Defined in: packages/react/src/admin/adminHref.ts:61

Builds an admin panel URL from a target and the project’s configured basePath — the one place every admin link in @vexcms/react (and, via re-export, @vexcms/next) computes a path. Replaces 30 hand-built `${basePath}/...` / hardcoded "/admin/..." call sites across the nav, breadcrumb, dashboard, list views, and all 16 field types’ Cell.tsx title links (Step 17 audit finding 7) — grep for adminHref( to confirm no hand-built admin URL remains outside this file.

"collections" is the collections-only index page at /{basePath}/collections (collections + media collections, permission-filtered — CollectionsIndexView), parallel to the pre-existing "globals" index at /{basePath}/globals (GlobalsListView). Collection targets resolve under /collections/ — /{basePath}/collections/{slug}, /{basePath}/collections/{slug}/{id} — and /{basePath}/{slug} 404s (launch spec H, no redirect). Global targets are unchanged: /{basePath}/globals/{slug}. The route parser NextAdminPage.tsx reads these same two first-segment shapes (collections[/<slug>[/<id>]], globals[/<slug>]) and notFound()s on anything else — a separate, pre-existing concern this function does not touch.

AdminHrefTarget

What the link points at.

string

The project’s configured VexClientConfig.basePath (e.g. config.basePath), leading-slash-normalized internally via addLeadingSlash the same way every replaced call site already did.

string

The absolute admin panel path for target.

adminHref({ type: "dashboard" }, "/admin"); // "/admin"
adminHref({ type: "collections" }, "/admin"); // "/admin/collections"
adminHref({ type: "collection", slug: "posts" }, "/admin"); // "/admin/collections/posts"
adminHref({ type: "global", slug: "siteSettings" }, "/admin"); // "/admin/globals/siteSettings"
adminHref({ type: "document", slug: "posts", id: "abc" }, "/admin"); // "/admin/collections/posts/abc"
adminHref({ type: "create", slug: "posts" }, "/admin"); // "/admin/collections/posts?createNew=true"