LinkedInBot访问动态URL时出现问题。

huangapple go评论69阅读模式
英文:

Issue with LinkedInBot accessing dynamic URLs incorrectly

问题

我目前面临的问题是LinkedInBot(在LinkedIn上共享页面时使用的工具)在我的Vercel托管的Next.js应用程序中不正确地访问动态URL。与访问预期的URL格式不同,LinkedInBot尝试访问带有方括号的路由参数的编码版本。

通常情况下,我能够访问页面[GET] /2023/07/como-implementar-diversidade-na-documentacao,它对应于[year]/[month]/[slug].tsx文件。它正常工作,但当我尝试在LinkedIn上分享链接时,会得到404错误,而在Vercel日志中,我发现LinkedInBot试图访问[GET] /%5Byear%5D/%5Bmonth%5D/%5Bslug%5D

页面的源代码:https://github.com/vtnorton/vtnorton.com/blob/main/src/pages/%5Byear%5D/%5Bmonth%5D/%5Bslug%5D.tsx

解决问题的尝试:

  • 我已验证在LinkedIn上分享的URL包含了带有正确动态值的URL。
  • 我已确保加载动态页面数据的逻辑正常工作。

NextJS版本:13.4.6

英文:

I'm currently facing an issue with the LinkedInBot (tool used for linkedin when you try to share one page on their platform) not accessing the dynamic URLs correctly in my Next.js application hosted on Vercel. Instead of accessing the expected URL format, the LinkedInBot is attempting to access an encoded version of the URL with route parameters enclosed in square brackets.

Normally I'm able to access the page [GET] /2023/07/como-implementar-diversidade-na-documentacao and it goes under the [year]/[month]/[slug].tsx file. It works fine, but when I try to share a link on LinkedIn it gets 404, ans in the Vercel Logs I found out that LinkedInBot tried to access [GET] /%5Byear%5D/%5Bmonth%5D/%5Bslug%5D instead.

Source code of the page: https://github.com/vtnorton/vtnorton.com/blob/main/src/pages/%5Byear%5D/%5Bmonth%5D/%5Bslug%5D.tsx

Attempts to solve the issue:

  • I have verified that the shared URL on LinkedIn contains the correct URL with dynamic values.
  • I have ensured that the logic for loading data for the dynamic pages is functioning correctly.

NextJS: 13.4.6

答案1

得分: 1

以下是责任所在的代码行。使用pageUrl时,所有参数都会出现相同的问题。根据Next.js官方文档

> pathname:字符串 - 当前路由文件的路径,位于/pages之后。因此,不包括basePathlocale和尾随斜杠(trailingSlash: true)。

因此,当我们在 https://vtnorton.com/2023/07/como-implementar-diversidade-na-documentacao 中检查您的页面时,它将会是精确的/[year]/[month]/[slug]

<meta property="og:url" content="https:`//vtnorton.com/[year]/[month]/[slug]">

相反,您可以使用asPath

> asPath:字符串 - 在浏览器中显示的路径,包括搜索参数,并遵循trailingSlash配置。不包括basePathlocale

我提了一个包含这些更改的PR:https://github.com/vtnorton/vtnorton.com/pull/38

英文:

These are the lines responsible for the issue. You have the same problem with all parameters using pageUrl. From the Next.js official documentation:

> pathname: String - The path for current route file that comes after /pages. Therefore, basePath, locale and trailing slash (trailingSlash: true) are not included.

So it will be exactly /[year]/[month]/[slug] as we can see when inspecting your page in https://vtnorton.com/2023/07/como-implementar-diversidade-na-documentacao :

<meta property="og:url" content="https:`//vtnorton.com/[year]/[month]/[slug]">

Instead, you could use asPath:

> asPath: String - The path as shown in the browser including the search params and respecting the trailingSlash configuration.
basePath and locale are not included.

I made a PR with the changes: https://github.com/vtnorton/vtnorton.com/pull/38

huangapple
  • 本文由 发表于 2023年7月13日 20:44:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76679527.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定