nextjs-routes

Type safe routing for Next.js

MIT License

Downloads
57.9K
Stars
568
Committers
10

Bot releases are hidden (Show)

nextjs-routes - v2.2.2-rc.4

Published by tatethurston 24 days ago

2.2.2

  • Adds support for Next.js's app directory. Link accepts either static routes (no url parameters) or a RouteLiteral string, which can be generated by the route helper from this library:

    import { route } from "nextjs-routes";
    
    <Link
      href={route({
        pathname: "/foos/[foo]",
        query: { foo: "bar" },
      })}
    >
      Baz
    </Link>;
    
  • Add RouteLiteral type. This type represents a string that confirmed to be a validated application route and can be passed to Link or useRouter. This is a TypeScript branded type.

    import { RouteLiteral } from "nextjs-routes";
    
  • Refine types for usePathname and useParams from "next/navigation" to use nextjs-routes generated types.

  • Fix generated routes when using parallel-routes and intercepting-routes.

  • Fix ref type for Link. Previously ref was missing, now it's correctly typed.

Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v2.2.2-rc.3...v2.2.2-rc.4

nextjs-routes - v2.2.2-rc.3

Published by tatethurston 29 days ago

2.2.2-rc.3

  • Adds support for Next.js's app directory. Link accepts either static routes (no url parameters) or a RouteLiteral string, which can be generated by the route helper from this library:

    import { route } from "nextjs-routes";
    
    <Link
      href={route({
        pathname: "/foos/[foo]",
        query: { foo: "bar" },
      })}
    >
      Baz
    </Link>;
    
  • Add RouteLiteral type. This type represents a string that confirmed to be a validated application route and can be passed to Link or useRouter. This is a TypeScript branded type.

    import { RouteLiteral } from "nextjs-routes";
    
  • Refine types for usePathname and useParams from "next/navigation" to use nextjs-routes generated types.

  • Fix generated routes when using parallel-routes and intercepting-routes.

nextjs-routes - v2.2.2-rc.2

Published by tatethurston 29 days ago

What's Changed

2.2.2-rc.2

  • Adds support for Next.js's app directory. Link accepts either static routes (no url parameters) or a RouteLiteral string, which can be generated by the route helper from this library:

    import { route } from "nextjs-routes";
    
    <Link
      href={route({
        pathname: "/foos/[foo]",
        query: { foo: "bar" },
      })}
    >
      Baz
    </Link>;
    
  • Add RouteLiteral type. This type represents a string that confirmed to be a validated application route and can be passed to Link or useRouter. This is a TypeScript branded type.

    import { RouteLiteral } from "nextjs-routes";
    
  • Refine types for usePathname and useParams from "next/navigation"

Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v2.2.2-rc.1...v2.2.2-rc.2

nextjs-routes - v2.2.2-rc.1

Published by tatethurston about 1 month ago

2.2.2

  • Adds support for Next.js's app directory. Link accepts either static routes (no url parameters) or a RouteLiteral string, which can be generated by the route helper from this library:

    import { route } from "nextjs-routes";
    
    <Link
      href={route({
        pathname: "/foos/[foo]",
        query: { foo: "bar" },
      })}
    >
      Baz
    </Link>;
    
  • Add RouteLiteral type. This type represents a string that confirmed to be a validated application route and can be passed to Link or useRouter. This is a TypeScript branded type.

    import { RouteLiteral } from "nextjs-routes";
    
nextjs-routes - v2.2.1 Latest Release

Published by tatethurston 4 months ago

What's Changed

  • Fix route generation on Windows. See #187. Thanks @AkanoCA!

New Contributors

Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v2.2.0...v2.2.1

nextjs-routes - v2.2.0

Published by tatethurston 5 months ago

What's Changed

  • Add trailingSlash option to route. See #168
  • Fix the generated optional catch all route type. See #183
  • Sort the generated route types lexicographically.

Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v2.1.0...v2.2.0

nextjs-routes - v2.1.0

Published by tatethurston 12 months ago

nextjs-routes - v2.0.1

Published by tatethurston over 1 year ago

2.0.1

  • Fix GetServerSidePropsContext and GetServerSidePropsResult types. Thanks @po4tion!

  • Change generated file location from nextjs-routes.d.ts to @types/nextjs-routes.d.ts. Thanks @po4tion!

    To preserve the old location, make the following change to your next.config.js:

    const nextRoutes = require("nextjs-routes/config");
    const withRoutes = nextRoutes({
    +  outDir: "",
    });
    

    Otherwise, delete your old nextjs-routes.d.ts once @types/nextjs-routes.d.ts is generated.

New Contributors

Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v2.0.0...v2.0.1

nextjs-routes - v2.0.0

Published by tatethurston over 1 year ago

What's Changed

  • Route type generation can now also be generated outside of next build / next dev by using npx nextjs-routes.
  • router.query types must now be narrowed using router.isReady. This ensures types are correct for pages that use Automatic Static Optimization.

Next's documentation notes the following:

During prerendering, the router's query object will be empty since we do not have query information to provide during this phase. After hydration, Next.js will trigger an update to your application to provide the route parameters in the query object.

See #117 for more context and discussion.

import { useRouter } from "next/router";

const router = useRouter<"/foos/[foo]">();
// query is now typed as `{ foo?: string | undefined }`. Previously this was `{ foo: string }` which was not safe for static optimized pages
router.query;

Updating useRouter call sites to check isReady will narrow the query type:

import { useRouter } from "next/router";

const router = useRouter<"/foos/[foo]">();
// query is now typed as `{ foo?: string | undefined }`. Previously this was `{ foo: string }` which was not safe for static optimized pages
router.query;

+ if (router.isReady) {
+  // query is typed as `{ foo: string }`
+  router.query;
+ }

Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v1.0.9...v2.0.0

nextjs-routes - v1.0.9

Published by tatethurston over 1 year ago

What's Changed

  • Enable Link and router methods to only update the route hash. Thanks @sitch!
  • Publish commonjs for route runtime so jest tests don't require transpilation for users. Thanks @panudetjt!
  • Add GetServerSideProps and GetServerSidePropsContext types. Thanks @slhck!

Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v1.0.8...v1.0.9

nextjs-routes - v1.0.8

Published by tatethurston over 1 year ago

nextjs-routes - v1.0.7

Published by tatethurston almost 2 years ago

1.0.7

  • Remove package.json version import. This resolves TypeError[ERR_IMPORT_ASSERTION_TYPE_MISSING]. See #115 for more context.

Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v1.0.6...v1.0.7

nextjs-routes - v1.0.6

Published by tatethurston almost 2 years ago

What's Changed

  • Fix bad publish of 1.0.5 (missing runtime)

Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v1.0.5...v1.0.6

nextjs-routes - v1.0.5

Published by tatethurston almost 2 years ago

What's Changed

  • The version of nextjs-routes is now included in the generated nextjs-routes.d.ts file.
  • Switch Link to use TypeScript unions instead of function overloading. Function overloading resulted in errors that were difficult for users to understand, and created issues for some use cases.

Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v1.0.4...v1.0.5

nextjs-routes - v1.0.4

Published by tatethurston almost 2 years ago

1.0.4

  • LinkProps now accept path strings for static routes:

    import { LinkProps } from "next/link";
    // previously this would error
    const props: LinkProps = { href: "/foo" };
    

Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v1.0.3...v1.0.4

nextjs-routes - v1.0.3

Published by tatethurston almost 2 years ago

1.0.3

  • The Route type now includes hash. This enables the following:

    // this will link to /foo#bar
    <Link href={{ pathname: "/foo", hash: "bar" }}>Foo</Link>
    

Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v1.0.2...v1.0.3

nextjs-routes - v1.0.2

Published by tatethurston almost 2 years ago

1.0.2

  • Link now accepts anchor props:

    <Link href="/dashboard" className="border-indigo-500">
      Dashboard
    </Link>
    

Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v1.0.1...v1.0.2

nextjs-routes - v1.0.1

Published by tatethurston almost 2 years ago

1.0.1

  • Update NextRouter type to keep query and pathname bound in a union. This allows you to use router from useRouter as an argument to router.push or router.replace:

    const router = useRouter();
    // reload the current page, preserving search parameters
    router.push(router, undefined, { locale: "fr" });
    

Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v1.0.0...v1.0.1

nextjs-routes - v1.0.0

Published by tatethurston almost 2 years ago

1.0.0

  • This library will now follow semantic versioning.

  • The previously deprecated direct invocation of nextjs-routes via npx nextjs-routes has been removed in favor of automatic regeneration via withRoutes. See #63 for the motivation behind this change or to voice any concerns.

Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.1.7...v1.0.0

nextjs-routes - v0.1.7

Published by tatethurston almost 2 years ago

0.1.7

  • Support Next 13 app (beta) directory

  • Add dir option to support non standard NextJS project structures such as Nx:

    // next.config.js
    const withRoutes = require("nextjs-routes/config")({ dir: __dirname });
    

    Thanks @alexgorbatchev for the contribution!

New Contributors

Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.1.6...v0.1.7

Package Rankings
Top 3.26% on Npmjs.org
Related Projects