tatethurston / nextjs-routes

Type safe routing for Next.js
MIT License
578 stars 21 forks source link

The Link doesn't accept dynamic routes as href #198

Closed KingMatrix1989 closed 1 month ago

KingMatrix1989 commented 2 months ago

I am using the latest version of the package and seems the Next Link component doesn't accept any dynamic route as href while I don't have the same issue with useRouter.

Here are the generated types:

 // ...
  type StaticRoute = Exclude<Route, { query: any }>["pathname"];

  export interface LinkProps
    extends Omit<NextLinkProps, "href" | "locale">,
      AnchorHTMLAttributes<HTMLAnchorElement> {
    href: StaticRoute | RouteLiteral;
    locale?: false;
  }

  type LinkReactElement = DetailedReactHTMLElement<
    {
      onMouseEnter?: MouseEventHandler<Element> | undefined;
      onClick: MouseEventHandler;
      href?: string | undefined;
      ref?: any;
    },
    HTMLElement
  >;

According to the above code, the href type can be only StaticRoute or RouteLiteral!!! Why did you ignore dynamic routes?

image

tatethurston commented 2 months ago

@KingMatrix1989 could you provide the following context for me?

KingMatrix1989 commented 2 months ago

@KingMatrix1989 could you provide the following context for me?

  • nextjs-routes version:
  • Are you using the pages directory, app directory, or both?
  • Are you using nextjs-routes via next.config.js or the CLI (npx nextjs-routes)?
  • nextjs version:
tatethurston commented 2 months ago

@KingMatrix1989 Next.js' App Router doesn't accept dynamic hrefs: https://nextjs.org/docs/messages/app-dir-dynamic-href you need to use a path, so I'm confused about the ask here.

KingMatrix1989 commented 1 month ago

@KingMatrix1989 Next.js' App Router doesn't accept dynamic hrefs: https://nextjs.org/docs/messages/app-dir-dynamic-href you need to use a path, so I'm confused about the ask here.

Yeah, you are right. You said it in the README and I didn't notice :)

tatethurston commented 1 month ago

v2.2.2-rc.4 is the latest version with app router support. I'll cut a non pre-release version of 2.2.2 here in the next week or two.