Lists the site's public URL paths and resolves a URL path to the page it serves, for static generation, catch-all routes and redirects. Accessible as lynkow.paths.

Access via: lynkow.paths

Methods

4 methods

clearCache

TypeScript
clearCache(): void

Clears the path lists and resolutions this client has cached, so the next read fetches fresh data. Only useful with cache: true. Call it when a slug or a published page changes.

Returns: void


list

TypeScript
list(options?: PathsListOptions & { market?: string }): Promise<PathsListResponse>

Lists the public URL paths of the site's published articles and blog categories, for static generation and sitemaps. In flat blog URL mode only root categories are listed. include: 'commerce' appends the product, product category and product collection pages, all built in the one locale of the read: call once per locale to list them all. With a locale, an article untranslated in it is listed at its fallback URL with isFallback: true. With cache: true, cached for 5 minutes.

Parameter

Type

Description

options

PathsListOptions & { market?: string }

locale and fallback pick the locale, include: 'commerce' adds the commerce pages, market (a mkt_... id) drops products hidden in that market.

Returns: Promise<PathsListResponse>

TypeScript
// Next.js generateStaticParams()
export async function generateStaticParams() {
  const { paths } = await lynkow.paths.list()
  return paths.map((p) => ({ slug: p.path.split('/').filter(Boolean) }))
}

// Article, category and commerce URLs, for a sitemap
const { paths } = await lynkow.paths.list({ include: 'commerce' })
const productUrls = paths.filter((p) => p.type === 'product').map((p) => p.path)

matchRedirect

TypeScript
matchRedirect(path: string, options?: BaseRequestOptions): Promise<Redirect | null>

Finds the redirect that covers a URL path: a redirect rule set in the admin, or an automatic locale redirect, always 301 with preserveQueryString: true. Resolves to null when no redirect matches. The SDK never caches the answer. Throws LynkowError BAD_REQUEST for an empty path.

Parameter

Type

Description

path

string

The URL path to check, such as '/old-page'.

options

BaseRequestOptions

Request options, such as fetchOptions.

Returns: Promise<Redirect | null>

TypeScript
// In a Next.js middleware
const redirect = await lynkow.paths.matchRedirect(pathname)
if (redirect) {
  return NextResponse.redirect(redirect.target, redirect.statusCode)
}
// No redirect, continue to normal page rendering

resolve

TypeScript
resolve(path: string, options?: BaseRequestOptions & { country?: string; market?: string }): Promise<ResolveResponse>

Resolves a URL path to the article, blog category or commerce page (product, product category, product collection) it serves: narrow the result on type. A path that matches nothing but a redirect covers resolves to type: 'redirect'. A commerce hit is the record plus structuredData when the client has a publishableKey, else a pointer { id, slug, path }: test 'structuredData' in result. A category hit carries its first 500 published articles, newest first. With cache: true, cached for 5 minutes. Throws LynkowError NOT_FOUND (apiCode PATH_NOT_FOUND) when nothing matches, and UNAUTHORIZED (STOREFRONT_KEY_REQUIRED) on a commerce path when the API rejects the client's key.

Parameter

Type

Description

path

string

The URL path to resolve, such as '/blog/tech/my-article' or '/products/blue-mug'.

options

BaseRequestOptions & { country?: string; market?: string }

locale resolves in that locale, fallback: false refuses a hit served in another locale, market and country scope a commerce record.

Returns: Promise<ResolveResponse>

TypeScript
import { renderJsonLdGraph } from 'lynkow'

const lynkow = createClient({ siteId: '...', publishableKey: 'lkw_pk_...' })
const result = await lynkow.paths.resolve('/products/blue-mug')

switch (result.type) {
  case 'content':
    console.log(result.content.title)
    break
  case 'category':
    console.log(result.category.name, result.contents.data.length)
    break
  case 'product':
    if ('structuredData' in result) {
      const jsonLd = renderJsonLdGraph(result.structuredData.graph)
    }
    break
  case 'redirect':
    console.log(result.redirect.target, result.redirect.statusCode)
    break
}