Repository: tatethurston/nextjs-routes
Pull request #89 (2022-10-28 00:47:48)

static routing
cc @MariaSolOs 

codecov[bot]: # [Codecov](https://codecov.io/gh/tatethurston/nextjs-routes/pull/89?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston) Report
Base: **0.00**% // Head: **0.00**% // No change to project coverage :thumbsup:
> Coverage data is based on head [(`183e0df`)](https://codecov.io/gh/tatethurston/nextjs-routes/pull/89?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston) compared to base [(`e586e7d`)](https://codecov.io/gh/tatethurston/nextjs-routes/commit/e586e7d73aa1a5573571400d33f572e2c0ee2f25?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston).
> Patch has no changes to coverable lines.

> :exclamation: Current head 183e0df differs from pull request most recent head 79e5da0. Consider uploading reports for the commit 79e5da0 to get more accurate results

<details><summary>Additional details and impacted files</summary>


```diff
@@    Coverage Diff     @@
##   main   #89   +/-   ##
==========================
==========================

```



Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/tatethurston/nextjs-routes/pull/89?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8f31390..a7fc19a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,14 @@
 
 ## 0.1.6
 
+- `nextjs-routes` now accepts path strings for static routes:
+
+  ```tsx
+  <Link href="/foo">Foo</Link>
+  ```
+
+  Thanks [@MariaSolOs](https://github.com/MariaSolOs) for the contribution!
+
 - `nextjs-routes` now uses function overloads for `Link` and `router.push` and `router.replace`. This yields better hints for typos in pathnames:
 
   ```tsx
diff --git a/examples/intl/nextjs-routes.d.ts b/examples/intl/nextjs-routes.d.ts
index 22d37ed..54de902 100644
--- a/examples/intl/nextjs-routes.d.ts
+++ b/examples/intl/nextjs-routes.d.ts
@@ -39,6 +39,7 @@ declare module "next/link" {
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   export interface LinkProps<Href extends Route | Query = Route | Query>
     extends Omit<NextLinkProps, "href" | "locale"> {
@@ -60,7 +61,7 @@ declare module "next/link" {
     props: PropsWithChildren<LinkProps<Route>>
   ): LinkReactElement;
   declare function Link(
-    props: PropsWithChildren<LinkProps<Route["pathname"]>>
+    props: PropsWithChildren<LinkProps<StaticRoute>>
   ): LinkReactElement;
   declare function Link(
     props: PropsWithChildren<LinkProps<Query>>
@@ -77,6 +78,7 @@ declare module "next/router" {
   export { default } from "next/dist/client/router";
 
   type NextTransitionOptions = NonNullable<Parameters<Router["push"]>[2]>;
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   interface TransitionOptions extends Omit<NextTransitionOptions, "locale"> {
     locale?: Locale | false;
@@ -107,7 +109,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     push(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
@@ -123,7 +125,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     replace(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
diff --git a/examples/typescript/types/nextjs-routes.d.ts b/examples/typescript/types/nextjs-routes.d.ts
index b0014f8..5f0855e 100644
--- a/examples/typescript/types/nextjs-routes.d.ts
+++ b/examples/typescript/types/nextjs-routes.d.ts
@@ -38,6 +38,7 @@ declare module "next/link" {
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   export interface LinkProps<Href extends Route | Query = Route | Query>
     extends Omit<NextLinkProps, "href" | "locale"> {
@@ -59,7 +60,7 @@ declare module "next/link" {
     props: PropsWithChildren<LinkProps<Route>>
   ): LinkReactElement;
   declare function Link(
-    props: PropsWithChildren<LinkProps<Route["pathname"]>>
+    props: PropsWithChildren<LinkProps<StaticRoute>>
   ): LinkReactElement;
   declare function Link(
     props: PropsWithChildren<LinkProps<Query>>
@@ -76,6 +77,7 @@ declare module "next/router" {
   export { default } from "next/dist/client/router";
 
   type NextTransitionOptions = NonNullable<Parameters<Router["push"]>[2]>;
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   interface TransitionOptions extends Omit<NextTransitionOptions, "locale"> {
     locale?: false;
@@ -102,7 +104,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     push(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
@@ -118,7 +120,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     replace(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
diff --git a/src/core.ts b/src/core.ts
index 1c462db..c36e212 100644
--- a/src/core.ts
+++ b/src/core.ts
@@ -152,6 +152,7 @@ declare module "next/link" {
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   export interface LinkProps<Href extends Route | Query = Route | Query>
     extends Omit<NextLinkProps, "href" | "locale"> {
@@ -173,7 +174,7 @@ declare module "next/link" {
     props: PropsWithChildren<LinkProps<Route>>
   ): LinkReactElement;
   declare function Link(
-    props: PropsWithChildren<LinkProps<Route["pathname"]>>
+    props: PropsWithChildren<LinkProps<StaticRoute>>
   ): LinkReactElement;
   declare function Link(
     props: PropsWithChildren<LinkProps<Query>>
@@ -190,6 +191,7 @@ declare module "next/router" {
   export { default } from "next/dist/client/router";
 
   type NextTransitionOptions = NonNullable<Parameters<Router["push"]>[2]>;
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   interface TransitionOptions extends Omit<NextTransitionOptions, "locale"> {
     locale?: ${!i18n.locales.length ? "false" : `Locale | false`};
@@ -222,7 +224,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     push(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
@@ -238,7 +240,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     replace(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;


Test patch:
diff --git a/e2e/nextjs-routes.d.ts b/e2e/nextjs-routes.d.ts
index d80c22d..ad96eee 100644
--- a/e2e/nextjs-routes.d.ts
+++ b/e2e/nextjs-routes.d.ts
@@ -36,6 +36,7 @@ declare module "next/link" {
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   export interface LinkProps<Href extends Route | Query = Route | Query>
     extends Omit<NextLinkProps, "href" | "locale"> {
@@ -57,7 +58,7 @@ declare module "next/link" {
     props: PropsWithChildren<LinkProps<Route>>
   ): LinkReactElement;
   declare function Link(
-    props: PropsWithChildren<LinkProps<Route["pathname"]>>
+    props: PropsWithChildren<LinkProps<StaticRoute>>
   ): LinkReactElement;
   declare function Link(
     props: PropsWithChildren<LinkProps<Query>>
@@ -74,6 +75,7 @@ declare module "next/router" {
   export { default } from "next/dist/client/router";
 
   type NextTransitionOptions = NonNullable<Parameters<Router["push"]>[2]>;
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   interface TransitionOptions extends Omit<NextTransitionOptions, "locale"> {
     locale?: false;
@@ -100,7 +102,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     push(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
@@ -116,7 +118,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     replace(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
diff --git a/e2e/typetest.tsx b/e2e/typetest.tsx
index c15e17f..6e96a97 100644
--- a/e2e/typetest.tsx
+++ b/e2e/typetest.tsx
@@ -10,6 +10,7 @@ function expectType<T>(_value: T) {}
 
 // Links with string hrefs
 <Link href="/" />;
+// @ts-expect-error dynamic paths are only valid with a UrlObject
 <Link href="/foos/[foo]" />;
 // @ts-expect-error bar isn't a valid path name
 <Link href="/bar" />;
diff --git a/src/__snapshots__/core.test.ts.snap b/src/__snapshots__/core.test.ts.snap
index b85eac5..dfa4c09 100644
--- a/src/__snapshots__/core.test.ts.snap
+++ b/src/__snapshots__/core.test.ts.snap
@@ -44,6 +44,7 @@ declare module "next/link" {
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   export interface LinkProps<Href extends Route | Query = Route | Query>
     extends Omit<NextLinkProps, "href" | "locale"> {
@@ -65,7 +66,7 @@ declare module "next/link" {
     props: PropsWithChildren<LinkProps<Route>>
   ): LinkReactElement;
   declare function Link(
-    props: PropsWithChildren<LinkProps<Route["pathname"]>>
+    props: PropsWithChildren<LinkProps<StaticRoute>>
   ): LinkReactElement;
   declare function Link(
     props: PropsWithChildren<LinkProps<Query>>
@@ -82,6 +83,7 @@ declare module "next/router" {
   export { default } from "next/dist/client/router";
 
   type NextTransitionOptions = NonNullable<Parameters<Router["push"]>[2]>;
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   interface TransitionOptions extends Omit<NextTransitionOptions, "locale"> {
     locale?: Locale | false;
@@ -125,7 +127,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     push(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
@@ -141,7 +143,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     replace(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
@@ -201,6 +203,7 @@ declare module "next/link" {
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   export interface LinkProps<Href extends Route | Query = Route | Query>
     extends Omit<NextLinkProps, "href" | "locale"> {
@@ -222,7 +225,7 @@ declare module "next/link" {
     props: PropsWithChildren<LinkProps<Route>>
   ): LinkReactElement;
   declare function Link(
-    props: PropsWithChildren<LinkProps<Route["pathname"]>>
+    props: PropsWithChildren<LinkProps<StaticRoute>>
   ): LinkReactElement;
   declare function Link(
     props: PropsWithChildren<LinkProps<Query>>
@@ -239,6 +242,7 @@ declare module "next/router" {
   export { default } from "next/dist/client/router";
 
   type NextTransitionOptions = NonNullable<Parameters<Router["push"]>[2]>;
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   interface TransitionOptions extends Omit<NextTransitionOptions, "locale"> {
     locale?: false;
@@ -265,7 +269,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     push(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
@@ -281,7 +285,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     replace(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
@@ -343,6 +347,7 @@ declare module "next/link" {
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   export interface LinkProps<Href extends Route | Query = Route | Query>
     extends Omit<NextLinkProps, "href" | "locale"> {
@@ -364,7 +369,7 @@ declare module "next/link" {
     props: PropsWithChildren<LinkProps<Route>>
   ): LinkReactElement;
   declare function Link(
-    props: PropsWithChildren<LinkProps<Route["pathname"]>>
+    props: PropsWithChildren<LinkProps<StaticRoute>>
   ): LinkReactElement;
   declare function Link(
     props: PropsWithChildren<LinkProps<Query>>
@@ -381,6 +386,7 @@ declare module "next/router" {
   export { default } from "next/dist/client/router";
 
   type NextTransitionOptions = NonNullable<Parameters<Router["push"]>[2]>;
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   interface TransitionOptions extends Omit<NextTransitionOptions, "locale"> {
     locale?: false;
@@ -407,7 +413,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     push(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
@@ -423,7 +429,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     replace(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
@@ -483,6 +489,7 @@ declare module "next/link" {
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   export interface LinkProps<Href extends Route | Query = Route | Query>
     extends Omit<NextLinkProps, "href" | "locale"> {
@@ -504,7 +511,7 @@ declare module "next/link" {
     props: PropsWithChildren<LinkProps<Route>>
   ): LinkReactElement;
   declare function Link(
-    props: PropsWithChildren<LinkProps<Route["pathname"]>>
+    props: PropsWithChildren<LinkProps<StaticRoute>>
   ): LinkReactElement;
   declare function Link(
     props: PropsWithChildren<LinkProps<Query>>
@@ -521,6 +528,7 @@ declare module "next/router" {
   export { default } from "next/dist/client/router";
 
   type NextTransitionOptions = NonNullable<Parameters<Router["push"]>[2]>;
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   interface TransitionOptions extends Omit<NextTransitionOptions, "locale"> {
     locale?: false;
@@ -547,7 +555,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     push(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
@@ -563,7 +571,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     replace(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
@@ -623,6 +631,7 @@ declare module "next/link" {
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   export interface LinkProps<Href extends Route | Query = Route | Query>
     extends Omit<NextLinkProps, "href" | "locale"> {
@@ -644,7 +653,7 @@ declare module "next/link" {
     props: PropsWithChildren<LinkProps<Route>>
   ): LinkReactElement;
   declare function Link(
-    props: PropsWithChildren<LinkProps<Route["pathname"]>>
+    props: PropsWithChildren<LinkProps<StaticRoute>>
   ): LinkReactElement;
   declare function Link(
     props: PropsWithChildren<LinkProps<Query>>
@@ -661,6 +670,7 @@ declare module "next/router" {
   export { default } from "next/dist/client/router";
 
   type NextTransitionOptions = NonNullable<Parameters<Router["push"]>[2]>;
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   interface TransitionOptions extends Omit<NextTransitionOptions, "locale"> {
     locale?: false;
@@ -687,7 +697,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     push(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
@@ -703,7 +713,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     replace(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
@@ -780,6 +790,7 @@ declare module "next/link" {
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   export interface LinkProps<Href extends Route | Query = Route | Query>
     extends Omit<NextLinkProps, "href" | "locale"> {
@@ -801,7 +812,7 @@ declare module "next/link" {
     props: PropsWithChildren<LinkProps<Route>>
   ): LinkReactElement;
   declare function Link(
-    props: PropsWithChildren<LinkProps<Route["pathname"]>>
+    props: PropsWithChildren<LinkProps<StaticRoute>>
   ): LinkReactElement;
   declare function Link(
     props: PropsWithChildren<LinkProps<Query>>
@@ -818,6 +829,7 @@ declare module "next/router" {
   export { default } from "next/dist/client/router";
 
   type NextTransitionOptions = NonNullable<Parameters<Router["push"]>[2]>;
+  type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
   interface TransitionOptions extends Omit<NextTransitionOptions, "locale"> {
     locale?: false;
@@ -844,7 +856,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     push(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;
@@ -860,7 +872,7 @@ declare module "next/router" {
       options?: TransitionOptions
     ): Promise<boolean>;
     replace(
-      url: Route["pathname"],
+      url: StaticRoute,
       as?: string,
       options?: TransitionOptions
     ): Promise<boolean>;