Developer use cases
Learn actions you can take to work with project maps.
Get a composition from project map#
The following example demonstrates how to list all compositions that are in a published state using the project map client (there are some exceptions).
In this example Uniform uses Dynamic Catch All Routes from Next.js to render all pages in single place, from Home page, to deep multilevel pages.
/pages/[[...path]].js
Get all compositions from project map#
An example to define the paths of the compositions to be static-generated:
Render links for link parameters#
By using the link parameter on components, editors can set links to other nodes. This ensures valid URLs even when the linked node is moved to another location within the project map. How these links are rendered in the frontend application is up to the developer to decide and implement.
Here is an example of a custom InternalLink
component that demonstrates how to render an internal link with the Link
parameter using the Next.js Link component
/src/components/InternalLink.js
Generate sitemap.xml#
Usually sitemap generation is your web framework task (also more reliable because of dynamic pages exceptions). But you can use Project Map API directly to fetch whole tree (tree or flat structure) data to construct it your self.
Next.js framework provides three ways to achieve it:
- Manual static file upload - https://nextjs.org/learn/seo/crawling-and-indexing/xml-sitemaps
- Generate via getServerSideProps - https://nextjs.org/learn/seo/crawling-and-indexing/xml-sitemaps. This is the only option where you'd need to use Project Map API
- Preferred option: Generate via npm package next-sitemap.
Generate navigation from project map#
The tree-like hierarchical structure of nodes in a project map make it easy to render navigational components using the project map client. Example use cases for navigation could be:
- Global navigation: Use project maps to render a main navigation or footer navigation
- Local navigation: Show links to sibling or child nodes of a specific node.
- Breadcrumb navigation: Show the trail of parent nodes of a specific node (such as
Home > Company > About us
).
Advanced or custom navigation
If you need to control the structure or display, or need to enrich your navigation with content or personalized links, Uniform recommends you create custom Canvas components that represent your navigation UI. This gives you a high level of flexibility as you can leverage all Canvas capabilities. Use link parameters in your components to connect your links with the project map.
To get the list of the top level project map nodes (for example, for a global navigation), you can use ProjectMapClient.getNodes
and set the depth
parameter to 1
:
To get the ancestors of a project map node (for example, for breadcrumb navigation), you can use ProjectMapClient.getNodes
and set the includeAncestors
parameter to true
: