@payloadpack/redirectsGuides
Use with localization
Build localized document paths, pass locales to findRedirect and suggestRedirects, and understand how From and notices work across locales.
When to use this
Section titled “When to use this”Your site uses Payload localization and a page’s URL varies by locale, such as /about-us and /om-oss or /sv/om-oss.
Skip this guide if every locale shares one path for a page and your URLs have no locale segment.
Prerequisites: Configure Payload localization and complete Installation.
Build localized document paths
Section titled “Build localized document paths”Use the locale argument in buildDocumentPath to build the document’s path for that locale:
redirectsPlugin({ collections: ['pages', 'posts'], buildDocumentPath: ({ collection, document, locale }) => { const path = collection === 'posts' ? `/blog/${document.slug}` : `/${document.slug}` return locale === 'sv' ? `/sv${path}` : path }, documentSelect: { slug: true }})With @payloadpack/path and localized: true, document.path already holds the path for locale. Add a leading locale segment only if your site’s URLs include one.
Look up redirects for a locale
Section titled “Look up redirects for a locale”Import findRedirect from @payloadpack/redirects and pass locale. The lookup reads a winning document target in that locale and passes locale to buildDocumentPath:
const { foundRedirect } = await findRedirect({ locale: 'sv', path: '/om-oss', payload })Check foundRedirect.to.type ('document' or 'url') if your site needs to tell whether the destination came from a document target or from a URL an editor wrote. See findRedirect.
Report localized moves
Section titled “Report localized moves”Include locale on each entry in changedPaths passed to suggestRedirects.
- A move in a locale is compared with other moves in that same locale and suggests a redirect from that locale’s old path to the document.
- When a collection keeps one path across all locales and reports the same move once per locale,
suggestRedirectswrites one suggestion. - With
@payloadpack/path,onPathsChangedalready setslocaleon each entry inchangedPaths.
How From and notices behave across locales
Section titled “How From and notices behave across locales”- One shared From: A redirect has one
fromfor every locale, so/om-ossand/about-usare separate redirects in the Redirects collection. - Notices in the editor’s locale: The notice on a moved document reads that document in the editor’s current locale, drafts included, and passes that locale to
buildDocumentPath. See How move suggestions work.