I recently got chance to help a team on a requirement where we needed to implement product detail pages using SitecoreAI wildcard pages.
The setup was:
- SitecoreAI
- Content SDK 1.3.2
- Next.js 15
- Next.js App Router
The requirement was to have a Product Details page configured as a wildcard (*) item in SitecoreAI and use the incoming URL to determine which product should be displayed.
For example, we wanted URLs such as:
/products/product-123
/products/product-456
/products/product-789
All of these URLs should use the same wildcard page layout, while the last part of the URL identifies the actual product.
The Initial Question
We raised a Sitecore support case because we wanted to understand the recommended way to implement the wildcard page resolver with the Content SDK and Next.js App Router.
The important part of the question was that we were using Content SDK, not the JSS SDK, and the application was using the Next.js App Router.
Initially, the Sitecore AI support agent provided some guidance and documentation links. We specifically asked for the query to be reviewed by a support engineer rather than relying only on the AI response.
The Basic Wildcard Page Setup
The first part is straightforward.
In SitecoreAI, create a wildcard page under the required route. For example, if the required URL structure is:
/products/<product-slug>
the content tree can contain a wildcard item under the products item.
The wildcard item is configured with the required presentation details, components and placeholders.
Once the wildcard item is published, Sitecore represents the wildcard route using the special ,-w-, token.
So instead of trying to resolve the layout using:
/products/product-123
the layout should be resolved using the wildcard route:
/products/,-w-,
The Important Separation
This is the part that I found most useful.
There are actually two different things happening:
- We need to determine which Sitecore item provides the page layout.
- We need to determine which product the visitor is requesting.
The wildcard item is responsible for the first part.
The URL segment is responsible for the second part.
So for:
/products/product-123
we don't necessarily ask Sitecore for layout information for /products/product-123.
Instead, we resolve the layout from:
/products/,-w-,
and separately keep product-123 for retrieving the product data.
Resolving the Wildcard Layout
The support response described the approach using the Layout Service.
For example, when calling the REST Layout Service, the route passed to the layout request would be the wildcard route:
const language = 'en';
const sitecoreRoutePath = '/products/,-w-,';
const layoutData = await layoutService.fetchLayoutData(
sitecoreRoutePath,
language
);
The important point is not the exact helper implementation above, but the route being supplied to Layout Service.
The incoming URL and the Sitecore layout route are two different pieces of information.
Getting the Product from the URL
Once Next.js receives a request such as:
/products/product-123
the application can extract the relevant URL segment from the catch-all route.
That value can then be used to retrieve the actual product data.
For example:
const productSlug = path[path.length - 1];
The application can then use that value to query the product source, such as Experience Edge GraphQL or another product system.
Conceptually, the flow becomes:
Incoming URL
|
v
/products/product-123
|
+----------------------+
| |
v v
Wildcard layout Product identifier
/products/,-w-, product-123
| |
v v
Sitecore layout Product data
| |
+----------+-----------+
|
v
Render the page
Why Use a Wildcard Layout?
One of the reasons for using this pattern is that potentially thousands of product URLs can share the same Sitecore layout.
For example:
/products/product-123
/products/product-456
/products/product-789
/products/product-1000
...
All of them can use the same wildcard item for their Sitecore presentation.
The product itself can come from another data source based on the URL.
This also has implications for caching and Experience Edge because the layout request can consistently target the wildcard item rather than creating a separate layout resolution for every external product URL.
One Important Caveat
The initial support response included an example using RestLayoutService from the JSS package.
However, our application was using the Sitecore Content SDK.
So I would not take the JSS code example and assume that it is directly applicable to a Content SDK implementation.
The important part of the support guidance is the architecture:
- Resolve the Sitecore layout using the wildcard route.
- Keep the original URL/path available to the application.
- Use the URL segment to identify the product.
- Fetch the product data independently.
- Render the product using the wildcard page layout.
The Architecture I Took Away From This
For me, the key takeaway from this support case was that a wildcard page is not really about making Sitecore understand every possible product URL.
Instead, the wildcard item acts as the reusable Sitecore page definition.
The application handles the dynamic part of the URL.
So the responsibilities can be thought of as:
| Responsibility | Handled By |
|---|---|
| Page layout | Sitecore wildcard item |
| Presentation details | SitecoreAI |
| Incoming URL | Next.js App Router |
| Product identifier | URL segment |
| Product data | Experience Edge or external product source |
Final Thoughts
Wildcard pages are particularly useful when the number of dynamic pages is large but the page structure is common.
Instead of creating a separate Sitecore page for every product, the wildcard item provides the common Sitecore presentation while the application resolves the actual product from the URL.
The important thing is to keep these two concepts separate: the Sitecore item that provides the layout and the URL value that identifies the dynamic entity.
That separation makes the implementation much easier to reason about, especially when working with Next.js App Router and Sitecore Content SDK.
Comments
Post a Comment