vercel / next.js

The React Framework
https://nextjs.org
MIT License
124.73k stars 26.62k forks source link

`redirects()` in `next.config.js` are not working for app schema URL #47778

Open BrodaNoel opened 1 year ago

BrodaNoel commented 1 year ago

Verify canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 21.6.0: Mon Dec 19 20:44:01 PST 2022; root:xnu-8020.240.18~2/RELEASE_X86_64
    Binaries:
      Node: 18.14.0
      npm: 9.3.1
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.2.5-canary.25
      eslint-config-next: 13.1.6
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/lingering-resonance-en9626

To Reproduce

  1. Click in the only link present in the website
  2. You can check the error in Network tab in developers' browser tools

Describe the Bug

In next.config.js redirects are not working when they are app schemas. Example:

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,

  async redirects() {
    return [
      {
        source: '/login-with-openid',
        destination: 'nofilter://login-with-openid',
        basePath: false,
        permanent: false,
      },
    ];
  },
};

module.exports = nextConfig;

If you open the codesandbox, and click on the link, it will navigate to a page that should REDIRECT to nofilter://. nofilter is an app. If you have getnofilter.com app installed, you will see it doesn't open because the location http header is wrong in the request.

Something is weird: In my prod version (using "next": "13.1.6",), the location http header is: nofilter:/login-with-openid (there is 1 slash missing), but in canary is nofilter:login-with-openid (there are 2 slashes missing).

Screen Shot 2023-04-01 at 01 30 44

^^^ Check in the bottom, the location http header. That's the one how is nofilter:/ in 13.1.6 and nofilter: in canary

Expected Behavior

The redirection should go to the proper one defined in the configurations (with double slash), as in: nofilter://login-with-openid

Which browser are you using? (if relevant)

Safari in the phone (where it will be used)

How are you deploying your application? (if relevant)

Push to the repo who Vercel is listening changes

BrodaNoel commented 1 year ago

If you have a Vercel URL if you want to reproduce it: https://nofilter-landing-ssr-git-canary-1-april-2023-brodanoel.vercel.app/

Nextjs config file there is:

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,

  async redirects() {
    return [
      {
        source: '/ios',
        destination:
          'https://apps.apple.com/app/nofilter-photo-spots/id1445583976',
        basePath: false,
        permanent: false,
      },
      {
        source: '/android',
        destination:
          'https://play.google.com/store/apps/details?id=app.no_filter.nofilter',
        basePath: false,
        permanent: false,
      },
      {
        source: '/login-with-openid',
        destination: 'nofilter://login-with-openid',
        basePath: false,
        permanent: false,
      },
    ];
  },
};

module.exports = nextConfig;
Screen Shot 2023-04-01 at 01 36 22
BrodaNoel commented 1 year ago
mikeyfarina commented 1 year ago

I believe i am experiencing the same issue here. I hope this thread will get a response. Any workarounds?