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

Support Next.js "Statically Typed Links" #1403

Closed
theoludwig opened this issue Oct 5, 2024 · 1 comment
Closed

Support Next.js "Statically Typed Links" #1403

theoludwig opened this issue Oct 5, 2024 · 1 comment
Labels
enhancement New feature or request unconfirmed Needs triage.

Comments

@theoludwig
Copy link

Is your feature request related to a problem? Please describe.

Make the functions from createSharedPathnamesNavigation (imported from next-intl/navigation) type safe when experimental.typedRoutes is enabled (in next.config.js).

Next.js documentation: https://nextjs.org/docs/app/building-your-application/configuring/typescript#statically-typed-links

Describe the solution you'd like

Type Safe routing with:

import { createSharedPathnamesNavigation } from "next-intl/navigation"

export const { Link, redirect, usePathname, useRouter } =
  createSharedPathnamesNavigation(routing)

I've used the same repo for the bug reproduction for #1402 but created another branch to try enabling experimental.typedRoutes: https://github.com/theoludwig/next-intl-bug-repro-relative-time-now/tree/typed-routes

Ideally we should be able to use the types generated in .next/types/link.d.ts, but ignore the slug [locale], and have type safe links, for example:

<Link href="/items">Items Page</Link>
{/* TypeScript Error! */}
<Link href="/do-not-exist-page">Items Page</Link>

Describe alternatives you've considered

No type-safety for links.

@theoludwig theoludwig added enhancement New feature or request unconfirmed Needs triage. labels Oct 5, 2024
@theoludwig
Copy link
Author

theoludwig commented Oct 5, 2024

Ah oops, a similar issue already exists.
Closing as it's a duplicate, sorry for the noise. 😅

#396

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

1 participant