shuding / nextra

Simple, powerful and flexible site generation framework with everything you love from Next.js.
https://nextra.site
MIT License
11.31k stars 1.24k forks source link

Core branch: SWR site redirects not working #384

Open robbear opened 2 years ago

robbear commented 2 years ago

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

shuding commented 2 years ago

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

tmm commented 1 year ago

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

evrifaessa commented 1 year ago

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 */ })```
sajatovic-a commented 1 year ago

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

d1onys1us commented 1 year ago

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,
      },
    ];
  },
});