Adds an afterChange hook to watched collections and a slug-redirects collection that stores the old slug along with the document ID. Next.js helpers for the App Router, Pages Router and an API route look up an old slug and redirect to the document's current slug. Requires Payload 3, Node.js 20 or later, and Next.js 14 or later for the helpers.
PayloadCMS plugin that automatically creates slug redirects when document slugs change
Installation
npm i payload-slug-redirects3
Stars
0
Forks
3
Open Issues
3 days ago
Last Updated
71
Weekly Downloads
v2.0.3
npm Version
51.4 KB
Unpacked Size
0
Dependencies
3+1 since Sep 7
| Date | Stars |
|---|---|
| Dec 6, 2026 | 3 |
| Dec 5, 2026 | 3 |
| Dec 4, 2026 | 3 |
| Dec 3, 2026 | 3 |
| Dec 2, 2026 | 3 |
| Dec 1, 2026 | 3 |
| Nov 30, 2026 | 3 |
| Nov 29, 2026 | 3 |
| Nov 28, 2026 | 3 |
| Nov 27, 2026 | 3 |
| Nov 26, 2026 | 3 |
| Nov 25, 2026 | 3 |
| Nov 24, 2026 | 3 |
| Nov 23, 2026 | 3 |
| Nov 22, 2026 | 3 |
| Nov 21, 2026 | 3 |
| Nov 20, 2026 | 3 |
| Nov 19, 2026 | 3 |
| Nov 18, 2026 | 3 |
| Nov 17, 2026 | 3 |
| Nov 16, 2026 | 3 |
| Nov 15, 2026 | 3 |
| Nov 14, 2026 | 3 |
| Nov 13, 2026 | 3 |
| Nov 12, 2026 | 3 |
| Nov 11, 2026 | 3 |
| Nov 10, 2026 | 3 |
| Nov 9, 2026 | 3 |
| Nov 8, 2026 | 3 |
| Nov 7, 2026 | 3 |
| Nov 6, 2026 | 3 |
| Nov 5, 2026 | 3 |
| Nov 4, 2026 | 3 |
| Nov 3, 2026 | 3 |
| Nov 2, 2026 | 3 |
| Nov 1, 2026 | 3 |
| Oct 31, 2026 | 3 |
| Oct 30, 2026 | 3 |
| Oct 29, 2026 | 3 |
| Oct 28, 2026 | 3 |
| Oct 27, 2026 | 3 |
| Oct 26, 2026 | 3 |
| Oct 25, 2026 | 3 |
| Oct 24, 2026 | 3 |
| Oct 23, 2026 | 3 |
| Oct 22, 2026 | 3 |
| Oct 21, 2026 | 3 |
| Oct 20, 2026 | 3 |
| Oct 19, 2026 | 3 |
| Oct 18, 2026 | 3 |
| Oct 17, 2026 | 3 |
| Oct 16, 2026 | 3 |
| Oct 15, 2026 | 3 |
| Oct 14, 2026 | 3 |
| Oct 13, 2026 | 3 |
| Oct 12, 2026 | 3 |
| Oct 11, 2026 | 3 |
| Oct 10, 2026 | 3 |
| Oct 9, 2026 | 3 |
| Oct 8, 2026 | 3 |
| Oct 7, 2026 | 3 |
| Oct 6, 2026 | 3 |
| Oct 5, 2026 | 3 |
| Oct 4, 2026 | 3 |
| Oct 3, 2026 | 3 |
| Oct 2, 2026 | 3 |
| Oct 1, 2026 | 3 |
| Sep 30, 2026 | 3 |
| Sep 29, 2026 | 3 |
| Sep 28, 2026 | 3 |
| Sep 27, 2026 | 3 |
| Sep 26, 2026 | 3 |
| Sep 25, 2026 | 2 |
| Sep 24, 2026 | 2 |
| Sep 23, 2026 | 2 |
| Sep 22, 2026 | 2 |
| Sep 21, 2026 | 2 |
| Sep 20, 2026 | 2 |
| Sep 19, 2026 | 2 |
| Sep 18, 2026 | 2 |
| Sep 17, 2026 | 2 |
| Sep 16, 2026 | 2 |
| Sep 15, 2026 | 2 |
| Sep 14, 2026 | 2 |
| Sep 13, 2026 | 2 |
| Sep 12, 2026 | 2 |
| Sep 11, 2026 | 2 |
| Sep 10, 2026 | 2 |
| Sep 9, 2026 | 2 |
| Sep 8, 2026 | 2 |
| Sep 7, 2026 | 2 |
88+55 since Sep 7
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 88 |
| Dec 5, 2026 | 87 |
| Dec 4, 2026 | 89 |
| Dec 3, 2026 | 104 |
| Dec 2, 2026 | 127 |
| Dec 1, 2026 | 132 |
| Nov 30, 2026 | 132 |
| Nov 29, 2026 | 110 |
| Nov 28, 2026 | 189 |
| Nov 27, 2026 | 303 |
| Nov 26, 2026 | 423 |
| Nov 25, 2026 | 426 |
| Nov 24, 2026 | 422 |
| Nov 23, 2026 | 420 |
| Nov 22, 2026 | 447 |
| Nov 21, 2026 | 364 |
| Nov 20, 2026 | 250 |
| Nov 19, 2026 | 162 |
| Nov 18, 2026 | 197 |
| Nov 17, 2026 | 199 |
| Nov 16, 2026 | 218 |
| Nov 15, 2026 | 366 |
| Nov 14, 2026 | 374 |
| Nov 13, 2026 | 385 |
| Nov 12, 2026 | 343 |
| Nov 11, 2026 | 281 |
| Nov 10, 2026 | 284 |
| Nov 9, 2026 | 270 |
| Nov 8, 2026 | 77 |
| Nov 7, 2026 | 77 |
| Nov 6, 2026 | 57 |
| Nov 5, 2026 | 67 |
| Nov 4, 2026 | 77 |
| Nov 3, 2026 | 83 |
| Nov 2, 2026 | 80 |
| Nov 1, 2026 | 100 |
| Oct 31, 2026 | 105 |
| Oct 30, 2026 | 144 |
| Oct 29, 2026 | 122 |
| Oct 28, 2026 | 105 |
| Oct 27, 2026 | 94 |
| Oct 26, 2026 | 93 |
| Oct 25, 2026 | 72 |
| Oct 24, 2026 | 69 |
| Oct 23, 2026 | 27 |
| Oct 22, 2026 | 47 |
| Oct 21, 2026 | 66 |
| Oct 20, 2026 | 68 |
| Oct 19, 2026 | 67 |
| Oct 18, 2026 | 72 |
| Oct 17, 2026 | 54 |
| Oct 16, 2026 | 62 |
| Oct 15, 2026 | 51 |
| Oct 14, 2026 | 39 |
| Oct 13, 2026 | 35 |
| Oct 12, 2026 | 35 |
| Oct 11, 2026 | 28 |
| Oct 10, 2026 | 33 |
| Oct 9, 2026 | 34 |
| Oct 8, 2026 | 51 |
| Oct 7, 2026 | 61 |
| Oct 6, 2026 | 61 |
| Oct 5, 2026 | 64 |
| Oct 4, 2026 | 66 |
| Oct 3, 2026 | 65 |
| Oct 2, 2026 | 60 |
| Oct 1, 2026 | 39 |
| Sep 30, 2026 | 31 |
| Sep 29, 2026 | 32 |
| Sep 28, 2026 | 29 |
| Sep 27, 2026 | 28 |
| Sep 26, 2026 | 27 |
| Sep 25, 2026 | 23 |
| Sep 24, 2026 | 31 |
| Sep 23, 2026 | 39 |
| Sep 22, 2026 | 41 |
| Sep 21, 2026 | 41 |
| Sep 20, 2026 | 57 |
| Sep 19, 2026 | 65 |
| Sep 18, 2026 | 80 |
| Sep 17, 2026 | 73 |
| Sep 16, 2026 | 65 |
| Sep 15, 2026 | 62 |
| Sep 14, 2026 | 64 |
| Sep 13, 2026 | 46 |
| Sep 12, 2026 | 38 |
| Sep 11, 2026 | 23 |
| Sep 10, 2026 | 22 |
| Sep 9, 2026 | 32 |
| Sep 8, 2026 | 33 |
| Sep 7, 2026 | 33 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1185354194-root)<a href="https://payloaddirectory.dev/plugins/1185354194-root"><img src="https://payloaddirectory.dev/badge/1185354194-root.svg" alt="Payload Directory"></a>README
Records slug changes in PayloadCMS v3 and gives your Next.js frontend what it needs to send visitors from an old URL to the current one.
Redirect records store the document ID instead of the destination slug, so after renames from A to B to C, both old URLs resolve to C.
pnpm add payload-slug-redirects
Requires PayloadCMS ^3.0.0 and Node.js 20 or later. The Next.js helpers require Next.js >=14.0.0.
// payload.config.ts
import { slugRedirectsPlugin } from 'payload-slug-redirects'
export default buildConfig({
plugins: [
slugRedirectsPlugin({
collections: ['posts', 'case-studies'],
}),
],
})
The plugin adds an afterChange hook to each watched collection and creates a slug-redirects collection. When a published document's slug changes, the hook records the old slug. When a visitor hits a URL with no matching document, the frontend helpers look up that slug and redirect to the document's current slug.
If a watched collection has no slug field, the plugin adds one. An existing field, including one from Payload's slugField(), is left alone.
| Site | Default field | Type |
|---|---|---|
| Single locale | slug | text |
| Multiple locales | localizedSlugs | json |
On multi-locale sites the hook needs every locale's slug on each save, but Payload only passes the current locale to afterChange for localized: true fields. Redirects are therefore tracked from a JSON field shaped like { "en": "my-post", "ar": "..." }.
The plugin creates localizedSlugs but does not fill it. Your project has to write that value on save, for example in a beforeChange hook. If it stays empty, no redirects are recorded.
| Option | Type | Default | Description |
|---|---|---|---|
collections | Array<string | CollectionEntry> | required | Collections to watch |
enabled | boolean | true | Disable the plugin without removing it |
locales | string[] | ['en'] | Locale codes to track |
slugField | string | see above | Field holding the slug |
revalidateUrl | string | -- | Called with the old slug after a change, in production only |
revalidateHeaders | Record<string, string> | -- | Headers for revalidation requests |
collection.name | string | 'slug-redirects' | Collection slug |
collection.visibleInTheUI | boolean | true | Show in the admin sidebar |
collection.onChange | (args) => void | Promise<void> | -- | Fires on any slug change |
Entries in collections can override slugField and add their own onChange:
slugRedirectsPlugin({
collections: [
'posts',
{
name: 'case-studies',
slugField: 'customSlugField',
onChange: ({ fromSlug, toSlug, locale, collectionType }) => {},
},
],
})
The helpers below also accept redirectsCollection for a custom collection.name, slugField when the frontend slug field is not slug, and fallbackLocale.
// app/[locale]/posts/[slug]/page.tsx
import { SlugRedirect } from 'payload-slug-redirects/next/app'
export default async function PostPage({ params }) {
const post = await getPost(params.slug, params.locale)
if (!post) {
return (
<SlugRedirect
slug={params.slug}
collectionType="posts"
locale={params.locale}
cmsUrl={process.env.CMS_URL!}
buildUrl={(slug, locale) => `/${locale}/posts/${slug}`}
/>
)
}
return <PostView post={post} />
}
SlugRedirect is a server component that calls permanentRedirect() (308) or notFound(). Pass permanent={false} for a 307.
// pages/posts/[slug].tsx, inside getStaticProps
import { resolveSlugRedirect } from 'payload-slug-redirects/next/pages'
if (!post) {
const redirect = await resolveSlugRedirect({
fromSlug: slug,
locale: locale ?? 'en',
collectionType: 'posts',
cmsUrl: process.env.NEXT_PUBLIC_CMS_API_URL!,
buildUrl: (s, l) => (l === 'ar' ? `/ar/posts/${s}` : `/posts/${s}`),
})
if (redirect) return redirect
return { notFound: true }
}
Pass permanent: false for a temporary redirect.
An optional endpoint for client-side lookups:
// pages/api/slug-redirects.ts
import { createSlugRedirectHandler } from 'payload-slug-redirects/next'
export default createSlugRedirectHandler({
cmsUrl: process.env.NEXT_PUBLIC_CMS_API_URL!,
})
GET /api/slug-redirects?fromSlug=old-slug&locale=en&collectionType=posts returns { slug: 'new-slug' }, or 404 if there is no redirect and 400 for invalid parameters.
Records hold fromSlug, locale, collectionType and documentId.
| Operation | Allowed for |
|---|---|
| Read | Everyone, because the Next.js helpers fetch without credentials |
| Create, update | Nobody except the plugin's hook |
| Delete | Users from the collection set in admin.user |
See CONTRIBUTING.md. Report vulnerabilities through SECURITY.md.
paths
Stored, queryable document paths for Payload page trees with publish-time uniqueness and a framework-agnostic resolver
60164/wk16v3
payload page tree
Folder-based hierarchical URL slugs with a visual page tree in the Payload admin
81536/wk19v3
redirects
Editor-managed redirects for Payload 4 with indexed lookups, regex support and move-based redirect suggestions
72187/wk10v4
redirects
Manage internal and external redirects from the Payload admin panel
100200.1k/wk46.1kv3 v4
nested docs
Official plugin for nesting Payload documents inside one another
100151.9k/wk46.1kv3 v4
payload redirect
Automatic and manual 301/302 redirect rules stored in a native Payload collection, with cycle validation
793.4k/wk0v3