{"id":13506561,"url":"https://github.com/nuxt-community/redirect-module","last_synced_at":"2025-05-15T03:04:11.665Z","repository":{"id":31874958,"uuid":"129966767","full_name":"nuxt-community/redirect-module","owner":"nuxt-community","description":"No more cumbersome redirects for Nuxt 2!","archived":false,"fork":false,"pushed_at":"2024-10-10T14:44:35.000Z","size":838,"stargazers_count":311,"open_issues_count":51,"forks_count":17,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-11T19:09:38.327Z","etag":null,"topics":["nuxt","nuxt-module","nuxt2","redirect","seo"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nuxt-community.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-17T21:23:02.000Z","updated_at":"2024-10-02T06:46:51.000Z","dependencies_parsed_at":"2023-12-29T23:22:27.205Z","dependency_job_id":"9c29e4a7-aec8-4469-b4a6-84c58eeb350b","html_url":"https://github.com/nuxt-community/redirect-module","commit_stats":{"total_commits":48,"total_committers":11,"mean_commits":4.363636363636363,"dds":0.5625,"last_synced_commit":"b9976cf12c5a8beed55c601cc77376c2b479e73d"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxt-community%2Fredirect-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxt-community%2Fredirect-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxt-community%2Fredirect-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxt-community%2Fredirect-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nuxt-community","download_url":"https://codeload.github.com/nuxt-community/redirect-module/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248368502,"owners_count":21092371,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nuxt","nuxt-module","nuxt2","redirect","seo"],"created_at":"2024-08-01T01:00:53.695Z","updated_at":"2025-04-11T09:35:18.565Z","avatar_url":"https://github.com/nuxt-community.png","language":"JavaScript","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# Redirect Module 🔀 No more **cumbersome** redirects!\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![Circle CI][circle-ci-src]][circle-ci-href]\n[![Codecov][codecov-src]][codecov-href]\n[![Dependencies][david-dm-src]][david-dm-href]\n[![Standard JS][standard-js-src]][standard-js-href]\n\n\u003e Nuxt 2 module to dynamically redirect initial requests\n \n[📖 **Release Notes**](./CHANGELOG.md)\n\n\n## Nuxt 3\n\nIn Nuxt 3 redirects are supported out of the box through [Route Rules](https://nuxt.com/docs/guide/concepts/rendering#hybrid-rendering), this module may not be needed.\n\n```ts\nexport default defineNuxtConfig({\n  routeRules: {\n   // Redirects legacy urls\n    '/old-page': { redirect: '/new-page' }\n  }\n})\n```\n\n## Features\n\nRedirecting URLs is an often discussed topic, especially when it comes to\nSEO. Previously it was hard to create a \"real\" redirect without performance\nloss or incorrect handling. But this time is over!\n\n## Setup\n\n1. Add the `@nuxtjs/redirect-module` dependency with `yarn` or `npm` to your project\n2. Add `@nuxtjs/redirect-module` to the `modules` section of `nuxt.config.js`:\n3. Configure it:\n\n```js\n{\n  modules: [\n    ['@nuxtjs/redirect-module', {\n      // Redirect option here\n    }]\n  ]\n}\n```\n\n### Using top level options\n\n```js\n{\n  modules: [\n    '@nuxtjs/redirect-module'\n  ],\n  redirect: [\n    // Redirect options here\n  ]\n}\n```\n\n## Options\n\n### `rules`\n\n- Default: `[]`\n\nRules of your redirects.\n\n### `onDecode`\n\n- Default: `(req, res, next) =\u003e decodeURI(req.url)`\n\nYou can set decode.\n\n### `onDecodeError`\n\n- Default: `(error, req, res, next) =\u003e next(error)`\n\nYou can set callback when there is an error in the decode.\n\n### `statusCode`\n\n- Default: `302`\n\nYou can set the default statusCode which gets used when no statusCode is defined on the rule itself.\n\n## Usage\n\nSimply add the links you want to redirect as objects to the module option array:\n\n```js\nredirect: [\n  { from: '^/myoldurl', to: '/mynewurl' }\n]\n```\n\nYou can set up a custom status code as well. By default, it's *302*!\n\n```js\nredirect: [\n  { from: '^/myoldurl', to: '/mynewurl', statusCode: 301 }\n]\n```\n\nAs you may have already noticed, we are leveraging the benefits of\n*Regular Expressions*. Hence, you can fully customize your redirects.\n\n```js\nredirect: [\n  { from: '^/myoldurl/(.*)$', to: '/comeallhere' }, // Many urls to one\n  { from: '^/anotherold/(.*)$', to: '/new/$1' } // One to one mapping\n]\n```\n\nFurthermore you can use a function to create your `to` url as well :+1:\nThe `from` rule and the `req` of the middleware will be provided as arguments.\nThe function can also be *async*!\n\n```js\nredirect: [\n  {\n    from: '^/someUrlHere/(.*)$',\n    to: (from, req) =\u003e {\n      const param = req.url.match(/functionAsync\\/(.*)$/)[1]\n      return `/posts/${param}`\n    }\n  }\n]\n```\n\nAnd if you really need more power... okay! You can also use a factory function\nto generate your redirects:\n\n```js\nredirect: async () =\u003e {\n  const someThings = await axios.get(\"/myApi\") // It'll wait!\n  return someThings.map(coolTransformFunction)\n}\n```\n\nNow, if you want to customize your redirects, how your decode is done\nor when there is some error in the decode, you can also:\n\n```js\nredirect: {\n  rules: [\n    { from: '^/myoldurl', to: '/mynewurl' }\n  ],\n  onDecode: (req, res, next) =\u003e decodeURI(req.url),\n  onDecodeError: (error, req, res, next) =\u003e next(error)\n}\n```\n\n**ATTENTION**: The factory function **must** return an array with redirect\nobjects (as seen above).\n\n## Gotchas\n\nThe redirect module will not work in combination with `nuxt generate`.\nRedirects are realized through a server middleware, which can only react when there is a server running.\n\n## Development\n\n1. Clone this repository\n2. Install dependencies using `yarn install` or `npm install`\n3. Start development server using `npm run dev`\n\n## License\n\n[MIT License](./LICENSE)\n\nCopyright (c) Alexander Lichter \u003cnpm@lichter.io\u003e\n\n\u003c!-- Badges --\u003e\n[npm-version-src]: https://img.shields.io/npm/dt/@nuxtjs/redirect-module.svg?style=flat-square\n[npm-version-href]: https://npmjs.com/package/@nuxtjs/redirect-module\n[npm-downloads-src]: https://img.shields.io/npm/v/@nuxtjs/redirect-module/latest.svg?style=flat-square\n[npm-downloads-href]: https://npmjs.com/package/@nuxtjs/redirect-module\n[circle-ci-src]: https://img.shields.io/circleci/project/github/nuxt-community/redirect-module.svg?style=flat-square\n[circle-ci-href]: https://circleci.com/gh/nuxt-community/redirect-module\n[codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/redirect-module.svg?style=flat-square\n[codecov-href]: https://codecov.io/gh/nuxt-community/redirect-module\n[david-dm-src]: https://david-dm.org/nuxt-community/redirect-module/status.svg?style=flat-square\n[david-dm-href]: https://david-dm.org/nuxt-community/redirect-module\n[standard-js-src]: https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square\n[standard-js-href]: https://standardjs.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuxt-community%2Fredirect-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnuxt-community%2Fredirect-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuxt-community%2Fredirect-module/lists"}