首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >NextJS在getServerSideProps内部重定向发送数据

NextJS在getServerSideProps内部重定向发送数据
EN

Stack Overflow用户
提问于 2022-11-24 10:04:24
回答 1查看 17关注 0票数 0

是否有可能在getServerSideProps函数中以类似于next.config.js的方式发送重定向数据(据我所知,next配置文件中无法传递隐藏查询)。

代码语言:javascript
运行
复制
export const getServerSideProps = async (context) => {
    const id = context.params.id;
    
    return {
        redirect: {
            destination: '/my-work',
            permanent: false,
            has: [
                {
                    type: 'query',
                    value: id
                }
            ]
        },
        props: {
                
        }
    }
}

我想把隐藏的查询传递到另一个页面,所以这只能作为中间件重定向,因为我是从电子邮件模板开始这个页面的。但是有对象不工作在getServerSideProps函数中。

还有其他方法来实现这一点吗?

谢谢你的帮忙!

EN

回答 1

Stack Overflow用户

发布于 2022-11-24 10:24:44

这是官方文件上的。

代码语言:javascript
运行
复制
module.exports = {
  async redirects() {
    return [
      // if the header `x-redirect-me` is present,
      // this redirect will be applied
      {
        source: '/:path((?!another-page$).*)',
        has: [
          {
            type: 'header',
            key: 'x-redirect-me',
          },
        ],
        permanent: false,
        destination: '/another-page',
      },
      // if the source, query, and cookie are matched,
      // this redirect will be applied
      {
        source: '/specific/:path*',
        has: [
          {
            type: 'query',
        key: 'page',
        // the page value will not be available in the
        // destination since value is provided and doesn't
        // use a named capture group e.g. (?<page>home)
        value: 'home',
      },
      {
        type: 'cookie',
        key: 'authorized',
        value: 'true',
      },
    ],
    permanent: false,
    destination: '/another/:path*',
  },
  // if the header `x-authorized` is present and
  // contains a matching value, this redirect will be applied
  {
    source: '/',
    has: [
      {
        type: 'header',
        key: 'x-authorized',
        value: '(?<authorized>yes|true)',
      },
    ],
    permanent: false,
    destination: '/home?authorized=:authorized',
  },
  // if the host is `example.com`,
  // this redirect will be applied
  {
    source: '/:path((?!another-page$).*)',
    has: [
      {
        type: 'host',
        value: 'example.com',
      },
    ],
    permanent: false,
    destination: '/another-page',
  },
]

},}

你可以和它比较一下。有关详细信息,请访问这里

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74558884

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档