├── cypress ├── test-server │ ├── .gitignore │ ├── pages │ │ ├── google.js │ │ ├── redirect.js │ │ ├── google-302.js │ │ ├── index.jsx │ │ └── client.js │ ├── package.json │ └── package-lock.json ├── fixtures │ └── example.json ├── support │ ├── index.js │ └── commands.js ├── plugins │ └── index.js └── integration │ └── redirect.js ├── .codesandbox └── ci.json ├── cypress.json ├── .gitignore ├── .editorconfig ├── .github └── workflows │ ├── cypress.yml │ └── static-export.yml ├── tsconfig.json ├── index.html ├── LICENSE ├── package.json ├── typings.d.ts ├── src └── index.tsx └── README.md /cypress/test-server/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .next 3 | out 4 | -------------------------------------------------------------------------------- /.codesandbox/ci.json: -------------------------------------------------------------------------------- 1 | { 2 | "sandboxes": ["nextjs-redirect-ci-x2m51"] 3 | } 4 | -------------------------------------------------------------------------------- /cypress.json: -------------------------------------------------------------------------------- 1 | { 2 | "baseUrl": "http://localhost:8123", 3 | "chromeWebSecurity": false, 4 | "retries": 3 5 | } -------------------------------------------------------------------------------- /cypress/test-server/pages/google.js: -------------------------------------------------------------------------------- 1 | import redirect from '../../..' 2 | export default redirect('https://google.com') 3 | -------------------------------------------------------------------------------- /cypress/test-server/pages/redirect.js: -------------------------------------------------------------------------------- 1 | import redirect from '../../..' 2 | export default redirect('to', { params: true }) 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | coverage* 4 | .nyc_output 5 | dist/ 6 | yarn.lock 7 | cypress/videos 8 | cypress/screenshots 9 | -------------------------------------------------------------------------------- /cypress/test-server/pages/google-302.js: -------------------------------------------------------------------------------- 1 | import redirect from '../../..' 2 | export default redirect('https://google.com', { statusCode: 302 }) 3 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | -------------------------------------------------------------------------------- /cypress/fixtures/example.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Using fixtures to represent data", 3 | "email": "hello@cypress.io", 4 | "body": "Fixtures are a great way to mock data for responses to routes" 5 | } 6 | -------------------------------------------------------------------------------- /cypress/test-server/pages/index.jsx: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | 3 | export default function Index() { 4 | return ( 5 |
6 | 7 | Redirect to Google 8 | 9 |
10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /cypress/test-server/pages/client.js: -------------------------------------------------------------------------------- 1 | import redirect from '../../..' 2 | 3 | const Redirect = redirect('https://pablopunk.com') 4 | 5 | export default function Client() { 6 | return ( 7 | 8 |

Redirecting...

9 |
10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /.github/workflows/cypress.yml: -------------------------------------------------------------------------------- 1 | name: Cypress Tests 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | cypress-run: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: checkout 10 | uses: actions/checkout@v1 11 | 12 | - name: npm install 13 | uses: bahmutov/npm-install@v1 14 | 15 | - name: Run tests 🧪 16 | run: npm run test:ci 17 | -------------------------------------------------------------------------------- /.github/workflows/static-export.yml: -------------------------------------------------------------------------------- 1 | name: Static export 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | cypress-run: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: checkout 10 | uses: actions/checkout@v1 11 | 12 | - name: npm install 13 | uses: bahmutov/npm-install@v1 14 | 15 | - name: Run tests 🧪 16 | run: npm run test:static-export 17 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "jsx": "react", 4 | "target": "es5", 5 | "lib": ["dom", "dom.iterable", "esnext"], 6 | "skipLibCheck": true, 7 | "strict": false, 8 | "noEmit": true, 9 | "esModuleInterop": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "allowJs": true 13 | }, 14 | "exclude": ["node_modules"], 15 | "include": ["./src/*.tsx", "./cypress/integration/*.js"] 16 | } 17 | -------------------------------------------------------------------------------- /cypress/test-server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nextjs-redirect-test", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "npm run build && next start -p 8123", 8 | "build": "next build", 9 | "dev": "next -p 8123" 10 | }, 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "next": "^12.1.0", 15 | "react": "^17.0.2", 16 | "react-dom": "^17.0.2" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | nextjs-redirect 10 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /cypress/support/index.js: -------------------------------------------------------------------------------- 1 | // *********************************************************** 2 | // This example support/index.js is processed and 3 | // loaded automatically before your test files. 4 | // 5 | // This is a great place to put global configuration and 6 | // behavior that modifies Cypress. 7 | // 8 | // You can change the location of this file or turn off 9 | // automatically serving support files with the 10 | // 'supportFile' configuration option. 11 | // 12 | // You can read more here: 13 | // https://on.cypress.io/configuration 14 | // *********************************************************** 15 | 16 | // Import commands.js using ES2015 syntax: 17 | import './commands' 18 | 19 | // Alternatively you can use CommonJS syntax: 20 | // require('./commands') 21 | -------------------------------------------------------------------------------- /cypress/plugins/index.js: -------------------------------------------------------------------------------- 1 | /// 2 | // *********************************************************** 3 | // This example plugins/index.js can be used to load plugins 4 | // 5 | // You can change the location of this file or turn off loading 6 | // the plugins file with the 'pluginsFile' configuration option. 7 | // 8 | // You can read more here: 9 | // https://on.cypress.io/plugins-guide 10 | // *********************************************************** 11 | 12 | // This function is called when a project is opened or re-opened (e.g. due to 13 | // the project's config changing) 14 | 15 | /** 16 | * @type {Cypress.PluginConfig} 17 | */ 18 | // eslint-disable-next-line no-unused-vars 19 | module.exports = (on, config) => { 20 | // `on` is used to hook into various events Cypress emits 21 | // `config` is the resolved Cypress config 22 | } 23 | -------------------------------------------------------------------------------- /cypress/support/commands.js: -------------------------------------------------------------------------------- 1 | // *********************************************** 2 | // This example commands.js shows you how to 3 | // create various custom commands and overwrite 4 | // existing commands. 5 | // 6 | // For more comprehensive examples of custom 7 | // commands please read more here: 8 | // https://on.cypress.io/custom-commands 9 | // *********************************************** 10 | // 11 | // 12 | // -- This is a parent command -- 13 | // Cypress.Commands.add('login', (email, password) => { ... }) 14 | // 15 | // 16 | // -- This is a child command -- 17 | // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) 18 | // 19 | // 20 | // -- This is a dual command -- 21 | // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) 22 | // 23 | // 24 | // -- This will overwrite an existing command -- 25 | // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Pablo Varela 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /cypress/integration/redirect.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | describe('nextjs-redirect', () => { 4 | it('redirects to google', () => { 5 | cy.visit('/google') 6 | cy.url().should('include', 'google.com') 7 | }) 8 | it('redirects with status 301 by default', () => { 9 | cy.request('/google').then((response) => { 10 | expect(response.redirects[0]).to.include('301:') 11 | }) 12 | }) 13 | it('redirects to dynamic custom url', () => { 14 | cy.request('/redirect?to=https://pablopunk.com').then((response) => { 15 | expect(response.redirects[0]).to.include('https://pablopunk.com') 16 | }) 17 | }) 18 | it('redirects with custom status', () => { 19 | cy.request('/google-302').then((response) => { 20 | expect(response.redirects[0]).to.include('302:') 21 | }) 22 | }) 23 | it('redirects in the client', () => { 24 | cy.visit('/client') 25 | cy.url().should('include', 'pablopunk.com') 26 | }) 27 | it('redirects with next/link', () => { 28 | cy.visit('/') 29 | cy.contains('Redirect to Google').click() 30 | cy.url().should('include', 'google.com') 31 | }) 32 | }) 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nextjs-redirect", 3 | "description": "Redirect to any URL in NextJS both in client and server", 4 | "version": "6.0.1", 5 | "author": "Pablo Varela ", 6 | "bugs": { 7 | "url": "https://github.com/pablopunk/nextjs-redirect/issues", 8 | "email": "pablo@pablopunk.com" 9 | }, 10 | "contributors": [ 11 | "Pablo Varela " 12 | ], 13 | "peerDependencies": { 14 | "next": "*", 15 | "react": "*" 16 | }, 17 | "devDependencies": { 18 | "@types/cypress": "^1.1.3", 19 | "@types/node": "^14.0.13", 20 | "@types/react": "^16.9.36", 21 | "cypress": "^9.3.1", 22 | "dts-bundle-generator": "^4.3.0", 23 | "husky": "*", 24 | "next": "*", 25 | "nodemon": "^2.0.16", 26 | "prettier": "*", 27 | "pretty-quick": "*", 28 | "react": "*", 29 | "start-server-and-test": "^1.14.0", 30 | "sucrase": "^3.20.3" 31 | }, 32 | "homepage": "https://github.com/pablopunk/nextjs-redirect", 33 | "keywords": [ 34 | "nextjs", 35 | "redirect", 36 | "zeit", 37 | "vercel", 38 | "react", 39 | "component", 40 | "automatic", 41 | "simple", 42 | "url", 43 | "302" 44 | ], 45 | "license": "MIT", 46 | "husky": { 47 | "hooks": { 48 | "pre-commit": "npm run build && pretty-quick --staged" 49 | } 50 | }, 51 | "prettier": { 52 | "semi": false, 53 | "singleQuote": true, 54 | "tabWidth": 2 55 | }, 56 | "repository": { 57 | "type": "git", 58 | "url": "https://github.com/pablopunk/nextjs-redirect" 59 | }, 60 | "scripts": { 61 | "build": "sucrase src -d dist --transforms imports,typescript,jsx && npm run generate-types", 62 | "dev": "nodemon --watch src/* --exec 'npm run build'", 63 | "generate-types": "dts-bundle-generator -o typings.d.ts src/index.tsx", 64 | "prepare": "npm run build", 65 | "cypress": "cypress open", 66 | "cypress:ci": "cypress run", 67 | "start-test-server": "npm run build && cd cypress/test-server && npm i && npm start", 68 | "start-test-server-dev": "cd cypress/test-server && npm run dev", 69 | "test:dev": "start-server-and-test start-test-server-dev http://localhost:8123 cypress", 70 | "test:ci": "start-server-and-test start-test-server http://localhost:8123 cypress:ci", 71 | "test:static-export": "cd cypress/test-server && npm i && npm run build && npx next export" 72 | }, 73 | "main": "./dist/index.js", 74 | "types": "./typings.d.ts", 75 | "files": [ 76 | "dist/index.js", 77 | "typings.d.ts" 78 | ] 79 | } 80 | -------------------------------------------------------------------------------- /typings.d.ts: -------------------------------------------------------------------------------- 1 | // Generated by dts-bundle-generator v4.3.0 2 | 3 | /// 4 | /// 5 | 6 | declare const _default: (redirectUrl: string, options?: { 7 | asUrl?: string; 8 | statusCode?: number; 9 | params?: boolean; 10 | }) => { 11 | new (props: {} | Readonly<{}>): { 12 | componentDidMount(): void; 13 | render(): JSX.Element; 14 | context: any; 15 | setState(state: {} | ((prevState: Readonly<{}>, props: Readonly<{}>) => {} | Pick<{}, K>) | Pick<{}, K>, callback?: () => void): void; 16 | forceUpdate(callback?: () => void): void; 17 | readonly props: Readonly<{}> & Readonly<{ 18 | children?: React.ReactNode; 19 | }>; 20 | state: Readonly<{}>; 21 | refs: { 22 | [key: string]: React.ReactInstance; 23 | }; 24 | shouldComponentUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): boolean; 25 | componentWillUnmount?(): void; 26 | componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void; 27 | getSnapshotBeforeUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>): any; 28 | componentDidUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>, snapshot?: any): void; 29 | componentWillMount?(): void; 30 | UNSAFE_componentWillMount?(): void; 31 | componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void; 32 | UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void; 33 | componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void; 34 | UNSAFE_componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void; 35 | }; 36 | new (props: {}, context: any): { 37 | componentDidMount(): void; 38 | render(): JSX.Element; 39 | context: any; 40 | setState(state: {} | ((prevState: Readonly<{}>, props: Readonly<{}>) => {} | Pick<{}, K>) | Pick<{}, K>, callback?: () => void): void; 41 | forceUpdate(callback?: () => void): void; 42 | readonly props: Readonly<{}> & Readonly<{ 43 | children?: React.ReactNode; 44 | }>; 45 | state: Readonly<{}>; 46 | refs: { 47 | [key: string]: React.ReactInstance; 48 | }; 49 | shouldComponentUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): boolean; 50 | componentWillUnmount?(): void; 51 | componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void; 52 | getSnapshotBeforeUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>): any; 53 | componentDidUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>, snapshot?: any): void; 54 | componentWillMount?(): void; 55 | UNSAFE_componentWillMount?(): void; 56 | componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void; 57 | UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void; 58 | componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void; 59 | UNSAFE_componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void; 60 | }; 61 | getInitialProps({ res, query }: { 62 | res: any; 63 | query: any; 64 | }): Promise<{}>; 65 | contextType?: React.Context; 66 | }; 67 | export default _default; 68 | 69 | export {}; 70 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Router from 'next/router' 3 | import Head from 'next/head' 4 | 5 | const PARAMS_ERROR = 6 | "Option {params: true} require the url to be the name of the param to search for: `redirect('to', {params:true})` will work with `/redirect?to=https://example.com`" 7 | 8 | const getParamFromClient = (paramName: string) => { 9 | if (typeof window === 'undefined') { 10 | return '' 11 | } 12 | 13 | const url = new URL(window.location.href) 14 | const paramValue = url.searchParams.get(paramName) 15 | 16 | if (!paramValue) { 17 | throw new Error(PARAMS_ERROR) 18 | } 19 | 20 | return paramValue 21 | } 22 | 23 | export default ( 24 | redirectUrl: string, 25 | options?: { asUrl?: string; statusCode?: number; params?: boolean } 26 | ) => 27 | class extends React.Component { 28 | // Redirects on the server side first if possible 29 | static async getInitialProps({ res, query }) { 30 | if (res?.writeHead) { 31 | let url = redirectUrl 32 | 33 | if (options?.params === true) { 34 | const param = redirectUrl 35 | if (!query?.[param]) { 36 | throw new Error(PARAMS_ERROR) 37 | } 38 | url = query[param] 39 | } 40 | res.writeHead(options?.statusCode ?? 301, { Location: url }) 41 | res.end() 42 | } else if (typeof window !== 'undefined') { 43 | let url = redirectUrl 44 | 45 | if (options?.params === true) { 46 | url = getParamFromClient(url) 47 | } 48 | window.location.href = url 49 | } 50 | 51 | return {} 52 | } 53 | 54 | // Redirects on the client with JavaScript if no server 55 | componentDidMount() { 56 | if (options?.params === true) { 57 | window.location.href = getParamFromClient(redirectUrl) 58 | } else if (options?.asUrl != null) { 59 | Router.push(redirectUrl, options.asUrl, { shallow: true }) 60 | } else if (redirectUrl[0] === '/') { 61 | Router.push(redirectUrl) 62 | } else { 63 | window.location.href = redirectUrl 64 | } 65 | } 66 | 67 | render() { 68 | let href = options?.asUrl ?? redirectUrl 69 | 70 | if (options?.params != null) { 71 | href = getParamFromClient(redirectUrl) 72 | } 73 | 74 | return ( 75 | <> 76 | 77 | {/* Redirects with meta refresh if no JavaScript support */} 78 | 81 | {(options?.statusCode === undefined || 82 | options?.statusCode === 301) && ( 83 | 84 | )} 85 | 86 | {/* Provides a redirect link if no meta refresh support; or children if provided */} 87 | {this.props.children ? ( 88 | this.props.children 89 | ) : ( 90 |

91 | Redirecting to {href}… 92 |

93 | )} 94 | 95 | ) 96 | } 97 | } 98 | 99 | const getParamFromURL = (url: string, param: string) => {} 100 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nextjs-redirect 2 | 3 |

4 | 5 | 6 | 7 |

8 | 9 |

10 | Redirect to any URL in NextJS both in client and server 11 |

12 | 13 | ## Install 14 | 15 | ```sh 16 | npm install nextjs-redirect 17 | ``` 18 | 19 | ## Usage 20 | 21 | Let's say you want to create a page `/donate` that redirects the user to paypal.me with a default value for the money. You create the page as you always do in NextJS (`pages/donate.js`) and then just use this component with the URL you want: 22 | 23 | ```js 24 | // pages/donate.js 25 | import redirect from 'nextjs-redirect' 26 | export default redirect('https://paypal.me/pablopunk/5') 27 | ``` 28 | 29 | You can checkout this example live in [pablopunk.com](https://pablopunk.com) 30 | 31 | ### Status code (301, 302...) 32 | 33 | By default, it will send a [301 status code](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection). This can be customized by an optional parameter: 34 | 35 | ```js 36 | redirect('https://google.es', { statusCode: 302 }) 37 | ``` 38 | 39 | ### Client side dynamic routes (as) 40 | 41 | When redirecting on the client side, if the redirected page is dynamic (`pages/user/[userId]/info.js`), the following redirect will trigger a page refresh: 42 | 43 | ```js 44 | redirect('/user/42/info') 45 | ``` 46 | 47 | In this case you can use the `asUrl` option to make a smooth transition between pages without any refresh: 48 | 49 | ```js 50 | redirect('/user/[userId]/info', { asUrl: '/user/42/info' }) 51 | ``` 52 | 53 | ### Static export 54 | 55 | This package is compatible with `next export` since version 4.0.0. See [PR #4](https://github.com/pablopunk/nextjs-redirect/pull/4) for more details. 56 | 57 | ### Custom UI component (HOC) 58 | 59 | In case the navigation is happening client-side, you can use this package as a HOC to provide your custom components/styles for the UI: 60 | 61 | ```jsx 62 | import redirect from 'nextjs-redirect' 63 | 64 | const Redirect = redirect('https://github.com/pablopunk') 65 | 66 | export default () => ( 67 | 68 | Redirecting to github! 69 | 70 | ) 71 | ``` 72 | 73 | ### Redirect to URL from parameters 74 | 75 | Let's say you have a single page called `/redirect`, and you wanna use it for all kinds of redirects: 76 | 77 | * `/redirect?to=https://google.com` 78 | * `/redirect?next=https://twitter.com` 79 | * `/redirect?url=https://pablopunk.com` 80 | 81 | Pretty cool huh!? You can do this with `nextjs-redirect` by passing the name of the parameter you want on the url. For the examples above: 82 | 83 | ```ts 84 | // NOTE: These are 3 separate examples, you can only choose one name per page 85 | redirect('to', {params: true}) 86 | redirect('next', {params: true}) 87 | redirect('url', {params: true}) 88 | ``` 89 | 90 | ## Related 91 | 92 | Working with locales routes? Take a look at [nextjs-redirect-locale](https://github.com/pablopunk/nextjs-redirect-locale). 93 | 94 | ## Native redirects 95 | 96 | There's now a native way of handling redirects on NextJS. You can read more about it [here](https://nextjs.org/blog/next-9-5#support-for-rewrites-redirects-and-headers). It requires you to modify your `next.config.js`. Personally I still think `nextjs-redirect` is a more friendly way of doing it, and also more flexible. For example you can do dynamic redirects on the server, depeding on the request, which is useful when working with locales (checkout [nextjs-redirect-locale](https://github.com/pablopunk/nextjs-redirect-locale)) and other request-dependent redirects. It also allows you make client redirects with a custom layout. 97 | 98 | ## License 99 | 100 | MIT 101 | 102 | ## Author 103 | 104 | | ![me](https://gravatar.com/avatar/fa50aeff0ddd6e63273a068b04353d9d?size=100) | 105 | | ---------------------------------------------------------------------------- | 106 | | [Pablo Varela](https://pablopunk.com) | 107 | -------------------------------------------------------------------------------- /cypress/test-server/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nextjs-redirect-test", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@next/env": { 8 | "version": "12.1.0", 9 | "resolved": "https://registry.npmjs.org/@next/env/-/env-12.1.0.tgz", 10 | "integrity": "sha512-nrIgY6t17FQ9xxwH3jj0a6EOiQ/WDHUos35Hghtr+SWN/ntHIQ7UpuvSi0vaLzZVHQWaDupKI+liO5vANcDeTQ==" 11 | }, 12 | "@next/swc-android-arm64": { 13 | "version": "12.1.0", 14 | "resolved": "https://registry.npmjs.org/@next/swc-android-arm64/-/swc-android-arm64-12.1.0.tgz", 15 | "integrity": "sha512-/280MLdZe0W03stA69iL+v6I+J1ascrQ6FrXBlXGCsGzrfMaGr7fskMa0T5AhQIVQD4nA/46QQWxG//DYuFBcA==", 16 | "optional": true 17 | }, 18 | "@next/swc-darwin-arm64": { 19 | "version": "12.1.0", 20 | "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-12.1.0.tgz", 21 | "integrity": "sha512-R8vcXE2/iONJ1Unf5Ptqjk6LRW3bggH+8drNkkzH4FLEQkHtELhvcmJwkXcuipyQCsIakldAXhRbZmm3YN1vXg==", 22 | "optional": true 23 | }, 24 | "@next/swc-darwin-x64": { 25 | "version": "12.1.0", 26 | "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-12.1.0.tgz", 27 | "integrity": "sha512-ieAz0/J0PhmbZBB8+EA/JGdhRHBogF8BWaeqR7hwveb6SYEIJaDNQy0I+ZN8gF8hLj63bEDxJAs/cEhdnTq+ug==", 28 | "optional": true 29 | }, 30 | "@next/swc-linux-arm-gnueabihf": { 31 | "version": "12.1.0", 32 | "resolved": "https://registry.npmjs.org/@next/swc-linux-arm-gnueabihf/-/swc-linux-arm-gnueabihf-12.1.0.tgz", 33 | "integrity": "sha512-njUd9hpl6o6A5d08dC0cKAgXKCzm5fFtgGe6i0eko8IAdtAPbtHxtpre3VeSxdZvuGFh+hb0REySQP9T1ttkog==", 34 | "optional": true 35 | }, 36 | "@next/swc-linux-arm64-gnu": { 37 | "version": "12.1.0", 38 | "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-12.1.0.tgz", 39 | "integrity": "sha512-OqangJLkRxVxMhDtcb7Qn1xjzFA3s50EIxY7mljbSCLybU+sByPaWAHY4px97ieOlr2y4S0xdPKkQ3BCAwyo6Q==", 40 | "optional": true 41 | }, 42 | "@next/swc-linux-arm64-musl": { 43 | "version": "12.1.0", 44 | "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-12.1.0.tgz", 45 | "integrity": "sha512-hB8cLSt4GdmOpcwRe2UzI5UWn6HHO/vLkr5OTuNvCJ5xGDwpPXelVkYW/0+C3g5axbDW2Tym4S+MQCkkH9QfWA==", 46 | "optional": true 47 | }, 48 | "@next/swc-linux-x64-gnu": { 49 | "version": "12.1.0", 50 | "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-12.1.0.tgz", 51 | "integrity": "sha512-OKO4R/digvrVuweSw/uBM4nSdyzsBV5EwkUeeG4KVpkIZEe64ZwRpnFB65bC6hGwxIBnTv5NMSnJ+0K/WmG78A==", 52 | "optional": true 53 | }, 54 | "@next/swc-linux-x64-musl": { 55 | "version": "12.1.0", 56 | "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-12.1.0.tgz", 57 | "integrity": "sha512-JohhgAHZvOD3rQY7tlp7NlmvtvYHBYgY0x5ZCecUT6eCCcl9lv6iV3nfu82ErkxNk1H893fqH0FUpznZ/H3pSw==", 58 | "optional": true 59 | }, 60 | "@next/swc-win32-arm64-msvc": { 61 | "version": "12.1.0", 62 | "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-12.1.0.tgz", 63 | "integrity": "sha512-T/3gIE6QEfKIJ4dmJk75v9hhNiYZhQYAoYm4iVo1TgcsuaKLFa+zMPh4056AHiG6n9tn2UQ1CFE8EoybEsqsSw==", 64 | "optional": true 65 | }, 66 | "@next/swc-win32-ia32-msvc": { 67 | "version": "12.1.0", 68 | "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-12.1.0.tgz", 69 | "integrity": "sha512-iwnKgHJdqhIW19H9PRPM9j55V6RdcOo6rX+5imx832BCWzkDbyomWnlzBfr6ByUYfhohb8QuH4hSGEikpPqI0Q==", 70 | "optional": true 71 | }, 72 | "@next/swc-win32-x64-msvc": { 73 | "version": "12.1.0", 74 | "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-12.1.0.tgz", 75 | "integrity": "sha512-aBvcbMwuanDH4EMrL2TthNJy+4nP59Bimn8egqv6GHMVj0a44cU6Au4PjOhLNqEh9l+IpRGBqMTzec94UdC5xg==", 76 | "optional": true 77 | }, 78 | "caniuse-lite": { 79 | "version": "1.0.30001303", 80 | "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001303.tgz", 81 | "integrity": "sha512-/Mqc1oESndUNszJP0kx0UaQU9kEv9nNtJ7Kn8AdA0mNnH8eR1cj0kG+NbNuC1Wq/b21eA8prhKRA3bbkjONegQ==" 82 | }, 83 | "js-tokens": { 84 | "version": "4.0.0", 85 | "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", 86 | "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" 87 | }, 88 | "loose-envify": { 89 | "version": "1.4.0", 90 | "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", 91 | "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", 92 | "requires": { 93 | "js-tokens": "^3.0.0 || ^4.0.0" 94 | } 95 | }, 96 | "nanoid": { 97 | "version": "3.2.0", 98 | "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.2.0.tgz", 99 | "integrity": "sha512-fmsZYa9lpn69Ad5eDn7FMcnnSR+8R34W9qJEijxYhTbfOWzr22n1QxCMzXLK+ODyW2973V3Fux959iQoUxzUIA==" 100 | }, 101 | "next": { 102 | "version": "12.1.0", 103 | "resolved": "https://registry.npmjs.org/next/-/next-12.1.0.tgz", 104 | "integrity": "sha512-s885kWvnIlxsUFHq9UGyIyLiuD0G3BUC/xrH0CEnH5lHEWkwQcHOORgbDF0hbrW9vr/7am4ETfX4A7M6DjrE7Q==", 105 | "requires": { 106 | "@next/env": "12.1.0", 107 | "@next/swc-android-arm64": "12.1.0", 108 | "@next/swc-darwin-arm64": "12.1.0", 109 | "@next/swc-darwin-x64": "12.1.0", 110 | "@next/swc-linux-arm-gnueabihf": "12.1.0", 111 | "@next/swc-linux-arm64-gnu": "12.1.0", 112 | "@next/swc-linux-arm64-musl": "12.1.0", 113 | "@next/swc-linux-x64-gnu": "12.1.0", 114 | "@next/swc-linux-x64-musl": "12.1.0", 115 | "@next/swc-win32-arm64-msvc": "12.1.0", 116 | "@next/swc-win32-ia32-msvc": "12.1.0", 117 | "@next/swc-win32-x64-msvc": "12.1.0", 118 | "caniuse-lite": "^1.0.30001283", 119 | "postcss": "8.4.5", 120 | "styled-jsx": "5.0.0", 121 | "use-subscription": "1.5.1" 122 | } 123 | }, 124 | "object-assign": { 125 | "version": "4.1.1", 126 | "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", 127 | "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" 128 | }, 129 | "picocolors": { 130 | "version": "1.0.0", 131 | "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", 132 | "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==" 133 | }, 134 | "postcss": { 135 | "version": "8.4.5", 136 | "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.5.tgz", 137 | "integrity": "sha512-jBDboWM8qpaqwkMwItqTQTiFikhs/67OYVvblFFTM7MrZjt6yMKd6r2kgXizEbTTljacm4NldIlZnhbjr84QYg==", 138 | "requires": { 139 | "nanoid": "^3.1.30", 140 | "picocolors": "^1.0.0", 141 | "source-map-js": "^1.0.1" 142 | } 143 | }, 144 | "react": { 145 | "version": "17.0.2", 146 | "resolved": "https://registry.npmjs.org/react/-/react-17.0.2.tgz", 147 | "integrity": "sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==", 148 | "requires": { 149 | "loose-envify": "^1.1.0", 150 | "object-assign": "^4.1.1" 151 | } 152 | }, 153 | "react-dom": { 154 | "version": "17.0.2", 155 | "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-17.0.2.tgz", 156 | "integrity": "sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==", 157 | "requires": { 158 | "loose-envify": "^1.1.0", 159 | "object-assign": "^4.1.1", 160 | "scheduler": "^0.20.2" 161 | } 162 | }, 163 | "scheduler": { 164 | "version": "0.20.2", 165 | "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.20.2.tgz", 166 | "integrity": "sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==", 167 | "requires": { 168 | "loose-envify": "^1.1.0", 169 | "object-assign": "^4.1.1" 170 | } 171 | }, 172 | "source-map-js": { 173 | "version": "1.0.2", 174 | "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz", 175 | "integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==" 176 | }, 177 | "styled-jsx": { 178 | "version": "5.0.0", 179 | "resolved": "https://registry.npmjs.org/styled-jsx/-/styled-jsx-5.0.0.tgz", 180 | "integrity": "sha512-qUqsWoBquEdERe10EW8vLp3jT25s/ssG1/qX5gZ4wu15OZpmSMFI2v+fWlRhLfykA5rFtlJ1ME8A8pm/peV4WA==" 181 | }, 182 | "use-subscription": { 183 | "version": "1.5.1", 184 | "resolved": "https://registry.npmjs.org/use-subscription/-/use-subscription-1.5.1.tgz", 185 | "integrity": "sha512-Xv2a1P/yReAjAbhylMfFplFKj9GssgTwN7RlcTxBujFQcloStWNDQdc4g4NRWH9xS4i/FDk04vQBptAXoF3VcA==", 186 | "requires": { 187 | "object-assign": "^4.1.1" 188 | } 189 | } 190 | } 191 | } 192 | --------------------------------------------------------------------------------