gpt4 book ai didi

reactjs - getServerSideProps 访问当前浏览器 url

转载 作者:行者123 更新时间:2023-12-04 14:09:24 25 4
gpt4 key购买 nike

我正在调用 getServerSideProps 并传入 req 和 res 参数,如下所示:

export async function getServerSideProps({ req, res }) {}
我需要获取当前浏览器 url 路径,但在请求对象中找不到它。
有没有办法在 getServerSideProps 中获取当前 url?

最佳答案

您可以使用 resolvedUrl来自 context 参数的字段,其中包含请求 URL 的规范化版本,包括查询字符串。

export async function getServerSideProps({ req, res, resolvedUrl }) {
console.log(resolvedUrl)

// Remaining code
}

关于reactjs - getServerSideProps 访问当前浏览器 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65617150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com