Search code examples
javascriptreactjsnext.jsexporeact-native-web

Redirect destination nextjs and react native expo web


I am trying to redirect a url to another url in my website as seen below, in nextjs and expo react native web.

I do not have an about page, but I have other pages under the about folder and would like to redirect any incoming request to /about path to the /about/company.

Below is my last implementation as seen in Nextjs next.config.js Redirects, and still I have not been able to get it to work.

const { withExpo } = require('@expo/next-adapter');
const withImages = require('next-images');
const withFonts = require('next-fonts');

module.exports = withExpo(
  withImages(
    withFonts({
      projectRoot: __dirname,
    })
  ), {
    async redirects() {
      return [
        {
          source: '/about',
          destination: '/about/company',
          permanent: true,
        },
      ];
    },
  }
);

Solution

  • moving the async redirects() into the innermost object withFonts worked, i.e.

    const { withExpo } = require('@expo/next-adapter');
    const withImages = require('next-images');
    const withFonts = require('next-fonts');
    
    module.exports = withExpo(
      withImages(
        withFonts({
          projectRoot: __dirname,
          async redirects() {
            return [
              {
                source: '/about',
                destination: '/about/company',
                permanent: true,
              },
            ];
          },
        })
      )
    );