nextra icon indicating copy to clipboard operation
nextra copied to clipboard

Core branch: SWR site redirects not working

Open robbear opened this issue 2 years ago • 3 comments

The SWR site example specifies redirects in next.config.js but these don't appear to be working. I'm actually looking for guidance on how to configure those redirects, myself.

Ex: /docs is supposed to redirect to /docs/getting-started but it leads instead to a 404

robbear avatar Mar 03 '22 17:03 robbear

This is related to the i18n middleware I believe. So if you don't have i18n enabled it should be working fine.

shuding avatar Mar 06 '22 09:03 shuding

As a workaround, you can use middleware.ts to handle redirects.

tmm avatar Dec 02 '22 23:12 tmm

I also couldn't find a way to use Next's inbuilt redirect functionality (https://nextjs.org/docs/api-reference/next.config.js/redirects).

Seems like we can pass other Next.js config as parameters but I don't know how I can pass the redirects() function as a parameter.

My configuration file is like so. Trying this way, the redirects didn't work:

const withNextra = require('nextra')({
    theme: 'nextra-theme-docs',
    themeConfig: './theme.config.tsx',
    staticImage: true,
    flexsearch: {
      codeblocks: false
    },
    defaultShowCopyCode: true,
    async redirects() {
      return [
        {
          source: '/test',
          destination: '/testing',
          permanent: true,
        },
      ]
    },
  })
   
  module.exports = withNextra()
   
  // If you have other Next.js configurations, you can pass them as the parameter:
  // module.exports = withNextra({ /* other next.js config */ })```

evrifaessa avatar Dec 05 '22 18:12 evrifaessa

Hi there @evrifaessa Maybe a silly thing, but did you try to restart a project... because redirect worked for me with the same config.

sajatovic-a avatar Jan 19 '23 22:01 sajatovic-a

I also couldn't find a way to use Next's inbuilt redirect functionality (https://nextjs.org/docs/api-reference/next.config.js/redirects).

Seems like we can pass other Next.js config as parameters but I don't know how I can pass the redirects() function as a parameter.

My configuration file is like so. Trying this way, the redirects didn't work:

const withNextra = require('nextra')({
    theme: 'nextra-theme-docs',
    themeConfig: './theme.config.tsx',
    staticImage: true,
    flexsearch: {
      codeblocks: false
    },
    defaultShowCopyCode: true,
    async redirects() {
      return [
        {
          source: '/test',
          destination: '/testing',
          permanent: true,
        },
      ]
    },
  })
   
  module.exports = withNextra()
   
  // If you have other Next.js configurations, you can pass them as the parameter:
  // module.exports = withNextra({ /* other next.js config */ })```

i fixed this by adding it to module.exports instead. here's my working snippet:

const withNextra = require("nextra")({
  defaultShowCopyCode: true,
  latex: true,
  theme: "nextra-theme-docs",
  themeConfig: "./theme.config.tsx",
});

module.exports = withNextra({
  async redirects() {
    return [
      {
        source: "/hello",
        destination: "/world",
        permanent: true,
      },
    ];
  },
});

dionysuzx avatar Jul 12 '23 18:07 dionysuzx