addRedirects

Beta
Beta

addRedirects

addRedirects

Add Redirects to your project.

await framer.addRedirects([
  { from: "/business", to: "/enterprise", expandToAllLocales: true },
])

Parameters

  • redirects: CreateRedirect[] – An array of objects representing the Redirects to add.

    • from: string – The path to redirect from.

    • to: string - The path to redirect to.

    • expandToAllLocales: boolean - Whether to expand the redirect to all Locales.

Returns

  • Promise<Redirect[]> – The added Redirects.

Errors

  • When the current user does not have permission to edit Site Settings, a FramerPluginPermissionError is thrown. Note: This is pending implementation and will be enabled after the Permission API PR is merged.

  • When the current Project is not on a Plan that includes Redirects, a FramerPluginLimitError with the code upsell is thrown. Also Framer will show a modal that asks the user to upgrade it's Plan.

  • When the Project Redirects reach the maximum allowed count, a FramerPluginLimitError with the code max-allowed-reached is thrown. Currently Framer allows up to 2500 Redirects per Project.

It's possible to use some basic regular expressions in Redirects.

from paths can contain wildcards, which will match any string. For example, you can redirect all pages under /faq/ to a new /support page by doing the following:

await framer.addRedirects([
  { from: "/faq/*", to: "/support", expandToAllLocales: false },
  { from: "/business", to: "/enterprise", expandToAllLocales: true },
])

It is also possible to capture those regular expression groups and pass them through to the to path. For example, if you moved your blog from /posts to /blog and wanted existing links to keep working, then you can do the following:

await framer.addRedirects([
  { from: "/posts/*", to: "/blog/:1", expandToAllLocales: false },
])

This would, for example, redirect /posts/getting-started to /blog/getting-started.