payloadpack

path

by payloadpack
plugins
Redirects & URLs
v4
^4.0.0-beta.12

Overview

Summary generated from the README

Adds a slug, a parent and a stored path to the collections you choose, so a site can find a document at a path with one indexed query. Moving or renaming a document updates everything below it, and each path belongs to one document across collections. It works with MongoDB, Postgres and SQLite and requires Payload 4.0.0-beta.12 or later.

Features

  • Stored path built from parent, slug and an optional base path such as /blog
  • Uniqueness across collections and drafts, with a refusal that names the conflicting document
  • Child paths follow when a page or post is renamed or moved
  • Home page at the root and configurable reserved segments
  • Optional per-locale paths with the locale kept out of the path
  • findByPath and findPaths helpers plus a path-aware relationship field

Use cases

  • Resolve nested page URLs in a Next.js catch-all route with a single database query
  • Build blog posts under a base path with optional parents
  • Serve localized sites where each language has its own slug and path

From the author

Stored URL paths for Payload 4 pages and posts. Editors pick a parent and a slug, and a site finds the document at a path in one indexed query, in any language.

Installation

npm i @payloadpack/path

10

Stars

0

Forks

0

Open Issues

1 weeks ago

Last Updated

270

Weekly Downloads

v0.4.1

npm Version

171.6 KB

Unpacked Size

0

Dependencies

Repository stars

10+10 since Oct 18

Show data
Repository stars by day (UTC)
DateStars
Dec 6, 202610
Dec 5, 202610
Dec 4, 202610
Dec 3, 202610
Dec 2, 202610
Dec 1, 202610
Nov 30, 202610
Nov 29, 202610
Nov 28, 20269
Nov 27, 20269
Nov 26, 20269
Nov 25, 20269
Nov 24, 20269
Nov 23, 20269
Nov 22, 20269
Nov 21, 20269
Nov 20, 20269
Nov 19, 20269
Nov 18, 202610
Nov 17, 20269
Nov 16, 20268
Nov 15, 20268
Nov 14, 20268
Nov 13, 20268
Nov 12, 20266
Nov 11, 20265
Nov 10, 20263
Nov 9, 20263
Nov 8, 20261
Nov 7, 20261
Nov 6, 20261
Nov 5, 20261
Nov 4, 20261
Nov 3, 20261
Nov 2, 20261
Nov 1, 20261
Oct 31, 20261
Oct 30, 20261
Oct 29, 20261
Oct 28, 20261
Oct 27, 20260
Oct 26, 20260
Oct 25, 20260
Oct 24, 20260
Oct 23, 20260
Oct 22, 20260
Oct 21, 20260
Oct 20, 20260
Oct 19, 20260
Oct 18, 20260

Shared by 3 plugins in payloadpack/plugins.

npm weekly downloads

331+331 since Nov 20

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 2026331
Dec 5, 2026718
Dec 4, 20261,030
Dec 3, 20261,050
Dec 2, 20261,067
Dec 1, 20261,167
Nov 30, 20261,262
Nov 29, 20261,819
Nov 28, 20261,782
Nov 27, 20261,444
Nov 26, 20261,409
Nov 25, 20261,362
Nov 24, 20261,165
Nov 23, 20261,011
Nov 22, 2026363
Nov 21, 20260
Nov 20, 20260

Each point is npm's rolling 7-day download count.

Health Score

75/100Excellent

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1428386015-path.svg)](https://payloaddirectory.dev/plugins/1428386015-path)
HTML
<a href="https://payloaddirectory.dev/plugins/1428386015-path"><img src="https://payloaddirectory.dev/badge/1428386015-path.svg" alt="Payload Directory"></a>
Updated Nov 26, 2026Created Oct 21, 2026Published Nov 26, 2026

README

@payloadpack/path

Stored URL paths for Payload 4 pages and posts.
Editors pick a parent and a slug, and your site finds the document at a path in one indexed query.

npm version Build status Payload version PolyForm Perimeter license

Documentation · Installation · Changelog · Contributing

What you get

  • 🧭 A stored path on every page and post, made from its parent and its slug, below an optional base path such as /blog
  • 🔒 One document per path, across all your collections and drafts too, and a refusal that names what is in the way
  • 🌳 Branches that move along: rename or move a page or a post, and everything below it follows
  • 🏠 A home page at /, and the slugs your site keeps for itself
  • 🌍 A path per language, with the locale left out of it
  • ⚡ One indexed query per collection to find what a path shows

Install

bun add @payloadpack/path
import { pathPlugin } from '@payloadpack/path'

export default buildConfig({
  plugins: [pathPlugin({ collections: ['pages', 'posts'] })]
})

Pages and posts now have a slug, a parent and their path in the sidebar. A page sits below a page and a post below a post. On Postgres or SQLite, create a migration for the new fields.

Then your site's catch-all route asks for the document at a path:

import { findByPath } from '@payloadpack/path'

const found = await findByPath({ path: '/about/team', payload })
// { collection: 'pages', document: { id, title, path: '/about/team', ... } }, or null

Transactions

The plugin works with database transactions and without them, on MongoDB, Postgres and SQLite.

With transactions, a save, move or delete that fails leaves everything as it was. Without them, which is SQLite's default, a move that stops halfway leaves some documents at their old paths, and backfillPaths puts them right.

Configure

KeyWhat it setsDefault
collectionsThe collections whose documents get a path, each by its slug or as { slug, basePath, parent, localized }, beside the ones wrapped in withPathnone
rootSlugThe slug that makes a top-level document the home page at /home
reservedSegmentsSegments your site serves itself, at the root or at any depth, as a list or each with whyPayload's admin and API routes
slugifyWhat makes a slug from a title and from what an editor types, as in Payload's own slug fieldAccents off Latin letters, other scripts kept
onPathsChangedA function that hears which paths changed, so you can purge your cache and keep your redirectsnone

A collection given as { slug: 'posts', basePath: '/blog' } puts its top-level documents below /blog, as in /blog/hello-world. The base path is optional, and a path still belongs to one document across all your collections.

Each collection decides where a document's parent comes from:

  • On its own, a collection gets the plugin's parent field, so a page sits below a page.
  • With parent: false its documents have no parent, so a post's path is /blog, a slash and its slug.
  • With Payload's own hierarchy on the collection, the plugin uses Payload's parent and you keep Payload's tree in the admin. There is nothing to set in the plugin for it.

A collection also takes slugField and parentField, which set Payload's own field options such as access on the plugin's fields, for example so that only a save in the default locale changes a slug.

A collection can also keep these settings in its own config, wrapped in withPath, which takes the same keys without slug. The plugin still has to be in plugins, and it adds the fields when it runs:

import { pathPlugin, withPath } from '@payloadpack/path'

const posts = withPath({ slug: 'posts', fields: [] }, { basePath: '/blog', parent: false })

export default buildConfig({
  collections: [posts],
  plugins: [pathPlugin()]
})

A relationship field in a block, a global or a collection is built when its file is imported, before the config exists, so it can't ask which collections have a path. Make it with pathRelationshipField, and pathPlugin() fills in the collections with a path when it runs:

import { pathRelationshipField } from '@payloadpack/path'

// Every collection with a path
pathRelationshipField({ name: 'doc', label: 'Document', required: true })

// Only these, each of which must have a path
pathRelationshipField({ name: 'doc', relationTo: ['pages'] })

It takes everything a relationship field takes except type. A relationTo you give is the field's from the start, in its order, and wherever the plugin finds the field it stops Payload when that list is empty or names a collection without a path. relationTo is always a list, so a value is stored as { relationTo, value } even with one collection, and offering a second one later needs no migration. The plugin finds the field anywhere in the config it gets. A field Lexical builds later, such as one in the fields of LinkFeature, isn't there yet, so give it relationTo: getPathCollectionSlugs(config) from the config that function gets, as the docs show.

getPathCollectionSlugs(config) lists the collections that get a path, in either way, for a plugin after pathPlugin(), a field's config function or payload.config, such as the fields of Lexical's LinkFeature.

Every option and every message an editor can meet are in the docs.

Languages

With localization, a collection's documents keep one slug and one path for every language, so a site that gets localization later keeps the paths it has. A collection given with localized: true has a path per locale instead, made from each locale's own slug, or from the slug it falls back to when it has none:

pathPlugin({ collections: [{ slug: 'pages', localized: true }] })

The locale is never part of the path, so your routes decide where it goes:

const found = await findByPath({ locale, path: `/${(segments ?? []).join('/')}`, payload })

With a path per locale, the same path may show different documents in different languages, and each language is published on its own. To link to a document in the other languages, findPaths({ collection, id, payload }) gives its path in each locale it is published in, and findByPath gives the same paths with the document when you pass paths: true.

Speed

A lookup is one indexed query per collection, and none for a path your site reserves.

The median and 95th percentile (p95) of each, on a database with 100,000 documents. Run on 2026-11-20, on Apple M3 Max with 128 GB of memory and Node 26.13.1.

Without localization:

OperationMongoDBPostgresSQLite
Lookup by path0.3 ms (p95 0.5 ms)0.5 ms (p95 0.7 ms)0.3 ms (p95 0.4 ms)
Autosave9.1 ms (p95 11 ms)4.6 ms (p95 5.4 ms)48 ms (p95 55 ms)
Publish, same slug9.2 ms (p95 15 ms)4.7 ms (p95 5.7 ms)29 ms (p95 34 ms)
Publish, new slug10 ms (p95 12 ms)6.7 ms (p95 9 ms)29 ms (p95 37 ms)
Move of 1,000 pages101 ms (p95 112 ms)185 ms (p95 196 ms)112 ms (p95 127 ms)

With localization (two locales):

OperationMongoDBPostgresSQLite
Lookup by path0.2 ms (p95 0.4 ms)0.6 ms (p95 0.8 ms)0.3 ms (p95 0.4 ms)
Autosave8.3 ms (p95 9.9 ms)5.4 ms (p95 6.3 ms)44 ms (p95 50 ms)
Publish, same slug8.7 ms (p95 10 ms)7.2 ms (p95 11 ms)26 ms (p95 30 ms)
Publish, new slug11 ms (p95 15 ms)8.2 ms (p95 14 ms)26 ms (p95 30 ms)
Move of 1,000 pages126 ms (p95 135 ms)352 ms (p95 370 ms)162 ms (p95 519 ms)

The speed page has what was measured, and how to run the benchmark yourself.

Requirements

Payload 4.0.0-beta.12 or later, with MongoDB, Postgres or SQLite.

License

Use it in any project, including client work you charge for and products you sell. What you can't do is offer the plugin, or a copy or fork of it, to others as a competing plugin, paid or free. The terms are the PolyForm Perimeter License 1.0.1.

Similar plugins