Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEXT-1203] Can't use external link with next/link and typedRoutes: true #49825

Closed
1 task done
jahirfiquitiva opened this issue May 15, 2023 · 1 comment · Fixed by #50066
Closed
1 task done

[NEXT-1203] Can't use external link with next/link and typedRoutes: true #49825

jahirfiquitiva opened this issue May 15, 2023 · 1 comment · Fixed by #50066
Assignees
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. Navigation Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@jahirfiquitiva
Copy link

jahirfiquitiva commented May 15, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.4.0: Mon Mar  6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000
    Binaries:
      Node: 16.20.0
      npm: 8.19.4
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.4.3-canary.0
      eslint-config-next: 13.4.2
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.0.4

Which area(s) of Next.js are affected? (leave empty if unsure)

Routing (next/router, next/navigation, next/link)

Link to the code that reproduces this issue

https://github.com/jahirfiquitiva/next-link-typed-error/

To Reproduce

  • Create a new Next.js project
  • Set experimental.typedRoutes in next.config.js
  • Link with an external URL will error

Describe the Bug

When setting experimental.typedRoutes to true in next.config.js, and using external URLs with next/link, a type error is shown, which can only be fixed by using as Route.

Type '"https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"' is not assignable to type 'UrlObject | RouteImpl<"https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app">'
Type error: "https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app" is not an existing route. If it is intentional, please type it explicitly with `as Route`.

Error logs: https://vercel.com/jahirfiquitiva/next-link-typed-error/9VkAtcfToKfdMMzxKq2ZM8x5f7yY

Possibly related: #47689

Expected Behavior

No error should be shown when using an external link, and it should be considered acceptable.
Should work normally as it does without typedRoutes

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Vercel

NEXT-1203

@jahirfiquitiva jahirfiquitiva added the bug Issue was opened via the bug report template. label May 15, 2023
@github-actions github-actions bot added the Navigation Related to Next.js linking (e.g., <Link>) and navigation. label May 15, 2023
@shuding shuding self-assigned this May 18, 2023
@shuding shuding added the linear: next Confirmed issue that is tracked by the Next.js team. label May 18, 2023
@shuding shuding changed the title Can't use external link with next/link and typedRoutes: true [NEXT-1203] Can't use external link with next/link and typedRoutes: true May 18, 2023
@kodiakhq kodiakhq bot closed this as completed in #50066 May 23, 2023
kodiakhq bot pushed a commit that referenced this issue May 23, 2023
This PR adds generated type definitions for `Link` hrefs with only search, hash or with a protocol.

Closes #49825.
fix NEXT-1203
hydRAnger pushed a commit to hydRAnger/next.js that referenced this issue Jun 12, 2023
This PR adds generated type definitions for `Link` hrefs with only search, hash or with a protocol.

Closes vercel#49825.
fix NEXT-1203
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. Navigation Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants