|
| 1 | +# Payload Redirects Plugin |
| 2 | + |
| 3 | +[](https://www.npmjs.com/package/@payloadcms/plugin-redirects) |
| 4 | + |
| 5 | +A plugin for [Payload CMS](https://github.com/payloadcms/payload) to easily manage your redirects. |
| 6 | + |
| 7 | +Core features: |
| 8 | + |
| 9 | +- Adds a `redirects` collection to your config that: |
| 10 | + - includes a `from` and `to` fields |
| 11 | + - allows `to` to be a document reference |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +```bash |
| 16 | + yarn add @payloadcms/plugin-redirects |
| 17 | + # OR |
| 18 | + npm i @payloadcms/plugin-redirects |
| 19 | +``` |
| 20 | + |
| 21 | +## Basic Usage |
| 22 | + |
| 23 | +In the `plugins` array of your [Payload config](https://payloadcms.com/docs/configuration/overview), call the plugin with [options](#options): |
| 24 | + |
| 25 | +```js |
| 26 | +import { buildConfig } from "payload/config"; |
| 27 | +import redirects from "@payloadcms/plugin-redirects"; |
| 28 | + |
| 29 | +const config = buildConfig({ |
| 30 | + collections: [ |
| 31 | + { |
| 32 | + slug: "pages", |
| 33 | + fields: [], |
| 34 | + }, |
| 35 | + ], |
| 36 | + plugins: [ |
| 37 | + redirects({ |
| 38 | + collections: ["pages"], |
| 39 | + }), |
| 40 | + ], |
| 41 | +}); |
| 42 | + |
| 43 | +export default config; |
| 44 | +``` |
| 45 | + |
| 46 | +### Options |
| 47 | + |
| 48 | +- `collections` : string[] | optional |
| 49 | + |
| 50 | + An array of collections slugs to populate in the `to` field of each redirect. |
| 51 | + |
| 52 | +- `overrides` : object | optional |
| 53 | + |
| 54 | + A partial collection config that allows you to override anything on the `redirects` collection. |
| 55 | + |
| 56 | +## TypeScript |
| 57 | + |
| 58 | +All types can be directly imported: |
| 59 | + |
| 60 | +```js |
| 61 | +import { PluginConfig } from "@payloadcms/plugin-redirects/types"; |
| 62 | +``` |
| 63 | + |
| 64 | +## Development |
| 65 | + |
| 66 | +To actively develop or debug this plugin you can either work directly within the demo directory of this repo, or link your own project. |
| 67 | + |
| 68 | +1. #### Internal Demo |
| 69 | + |
| 70 | + This repo includes a fully working, self-seeding instance of Payload that installs the plugin directly from the source code. This is the easiest way to get started. To spin up this demo, follow these steps: |
| 71 | + |
| 72 | + 1. First clone the repo |
| 73 | + 1. Then, `cd YOUR_PLUGIN_REPO && yarn && cd demo && yarn && yarn dev` |
| 74 | + 1. Now open `http://localhost:3000/admin` in your browser |
| 75 | + 1. Enter username `[email protected]` and password `test` |
| 76 | + |
| 77 | + That's it! Changes made in `./src` will be reflected in your demo. Keep in mind that the demo database is automatically seeded on every startup, any changes you make to the data get destroyed each time you reboot the app. |
| 78 | + |
| 79 | +1. #### Linked Project |
| 80 | + |
| 81 | + You can alternatively link your own project to the source code: |
| 82 | + |
| 83 | + 1. First clone the repo |
| 84 | + 1. Then, `cd YOUR_PLUGIN_REPO && yarn && cd demo && cp env.example .env && yarn && yarn dev` |
| 85 | + 1. Now `cd` back into your own project and run, `yarn link @payloadcms/plugin-redirects` |
| 86 | + 1. If this plugin using React in any way, continue to the next step. Otherwise skip to step 7. |
| 87 | + 1. From your own project, `cd node_modules/react && yarn link && cd ../react-dom && yarn link && cd ../../` |
| 88 | + 1. Then, `cd YOUR_PLUGIN_REPO && yarn link react react-dom` |
| 89 | + |
| 90 | + All set! You can now boot up your own project as normal, and your local copy of the plugin source code will be used. Keep in mind that changes to the source code require a rebuild, `yarn build`. |
| 91 | + |
| 92 | +## Screenshots |
0 commit comments