Project Map Client SDK
The Project Map Client (ProjectMapClient from @uniformdev/project-map) provides programmatic access to Uniform's project map -- the hierarchical site structure that maps URL paths to compositions. Use it for building navigation menus, generating sitemaps, resolving locale-specific paths, and working with site structure data.
Installation#
Initializing the client#
Standalone usage#
Within the App Router SDK#
The SDK provides a pre-configured client via getProjectMapClient:
Getting project map definitions#
A Uniform project can have multiple project maps. Retrieve the available definitions:
Get a specific definition by ID:
Getting nodes#
Flat node list#
getNodes returns project map nodes in a flat list format. This is useful for sitemaps, breadcrumbs, or any scenario where you need a flat list of pages:
Node properties#
Each ProjectMapNode contains:
| Property | Type | Description |
|---|---|---|
id | string | Unique node identifier |
path | string | URL path (e.g., /about, /blog/:slug) |
name | string | Display name |
type | string | Node type: composition, placeholder, redirect, or alias |
compositionId | string | Linked composition ID (when type is composition) |
compositionData | object | Composition metadata including editions and locales |
locales | object | Locale-specific path overrides |
data | object | Custom node data |
Query options#
getNodes accepts these parameters:
| Option | Type | Description |
|---|---|---|
projectMapId | string | Required. The project map definition ID. |
path | string | Filter nodes starting at this path. |
depth | number | How many levels deep to traverse. |
includeDescendants | boolean | Include all descendant nodes. |
compositionId | string | Find the node for a specific composition. |
Getting subtrees#
getSubtree returns nodes in a tree structure with parent/child/sibling references. This is ideal for building navigation menus:
ProjectMapSubtree#
The subtree node extends ProjectMapNode with navigation references:
| Property | Type | Description |
|---|---|---|
children | ProjectMapSubtree[] | Child nodes |
parent | ProjectMapSubtree | Parent node (references stripped to prevent circular refs) |
previousSibling | ProjectMapSubtree | Previous sibling node |
nextSibling | ProjectMapSubtree | Next sibling node |
Building navigation#
A practical example of building a site navigation from the project map:
Locale path resolution#
Use getNodeLocalePath to resolve the correct URL path for a given locale. If a node has locale-specific path overrides, this utility returns the override; otherwise it falls back to the default path:
Alternate locale URLs#
Use getRouteAlternateLocalesUrls to generate all locale-specific URLs for a composition route. This is useful for hreflang tags and language switchers:
Usage in a <head> element:
Active edition resolution#
When using content editions (locale-specific composition variants), use getNodeActiveCompositionEdition to resolve the correct edition for a given locale:
| Option | Type | Description |
|---|---|---|
node | ProjectMapNode | The node to resolve the edition for |
targetLocale | string | undefined | Locale to match. When undefined, returns the default. |
fallbackWhenLocaleNotMatched | boolean | When true, falls back to default if no edition matches the locale. Default: false. |
Route matching utility#
The Route class provides route pattern matching with dynamic segments (:paramName):
Generating a sitemap#
Combine getNodes with route resolution to generate a sitemap:
UncachedProjectMapClient#
For scenarios that require bypassing the API cache (e.g., admin scripts, preview modes), use UncachedProjectMapClient:
Import reference#
| Export | Package | Description |
|---|---|---|
ProjectMapClient | @uniformdev/project-map | Main project map client |
UncachedProjectMapClient | @uniformdev/project-map | Cache-bypassing client |
getNodeLocalePath | @uniformdev/project-map | Resolve locale-specific path for a node |
getRouteAlternateLocalesUrls | @uniformdev/project-map | Generate all locale URLs for a route |
getNodeActiveCompositionEdition | @uniformdev/project-map | Resolve active edition for a locale |
Route | @uniformdev/project-map | Route pattern matching and expansion |
getProjectMapClient | @uniformdev/next-app-router | Pre-configured client (server-only, App Router) |