Bot releases are hidden (Show)
Published by tatethurston almost 2 years ago
Accept path strings for static routes:
<Link href="/foo">Foo</Link>
Thanks @MariaSolOs for the contribution!
Use function overloads for Link
and router.push
and router.replace
. This yields better hints for typos in pathnames:
<Link href={{ pathname: "/foosy/[foo]" }}>Foo</Link>
Previously:
[tsserver 2322] [E] Type '"/foos/[foo]"' is not assignable to type '"/"'.
Now:
Type '"/foosy/[foo]"' is not assignable to type '"/api/hello" | "/bars/[bar]" | "/foos/[foo]" | "/"'. Did you mean '"/foos/[foo]"'?
(+2 other overload errors).
Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.1.5...v0.1.6
Published by tatethurston about 2 years ago
Export Locale
from nextjs-routes
.
import { Locale } from "nextjs-routes";
Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.1.4...v0.1.5
Published by tatethurston about 2 years ago
nextjs-routes
now generates route types for Nextjs i18n configuration. Eg the following next config:module.exports = withRoutes({
i18n: {
defaultLocale: "de-DE",
locales: ["de-DE", "en-FR", "en-US"],
},
});
Will make locale
typed as 'de-DE' | 'en-FR' | 'en-US'
for Link
and useRouter
.
Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.1.3...v0.1.4
Published by tatethurston about 2 years ago
nextjs-routes
pageExtensions has been updated to respect multiple extensions such as .page.tsx
. In 0.1.2
, only single extensions .tsx
were respected. This is now identical behavior to Next.js. Thanks @Elindorath!Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.1.2...v0.1.3
Published by tatethurston about 2 years ago
nextjs-routes
now respects pageExtensions from next.config.js
.Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.1.1...v0.1.2
Published by tatethurston about 2 years ago
[skipped]
Published by tatethurston about 2 years ago
This release contains a breaking change, indicated by the minor version bump to 0.1.0. nextjs-routes
has not yet reached v1, but will follow semantic versioning once it does. Until then, minor version changes will be used to help flag breaking changes.
withRoutes
import path and invocation has changed to better align with the general pattern in the Nextjs plugin ecosystem and to support configuration options, notably the new outDir
option. It also now includes an ESM export to support usage in next.config.mjs
.- const { withRoutes } = require("nextjs-routes/next-config.cjs");
+ const withRoutes = require("nextjs-routes/config")();
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
};
module.exports = withRoutes(nextConfig);
Note the import path has changed and the import itself has changed to function that is invoked with any configuration options. This provides better ergonomics for configuration options:
const withRoutes = require("nextjs-routes/config")({ outDir: "types" });
The type RoutedQuery
has been added to retrieve the Query
for a given Route
. This is useful as the context type parameter inside getStaticProps
and getServerSideProps
. Thanks @MariaSolOs for the contribution!
withRoutes
now accepts outDir
as a configuration option to dictate where nextjs-routes.d.ts
is generated. Thanks @MariaSolOs for the contribution!
Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.0.22...v0.1.0
Published by tatethurston about 2 years ago
Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.0.21...v0.0.22
Published by tatethurston about 2 years ago
route
runtime for generating type safe paths from a Route
objectThis can be used to fetch from API routes:
import { route } from "nextjs-routes";
fetch(route({ pathname: "/api/foos/[foo]", query: { foo: "foobar" } }));
Or for type safe redirects from getServerSideProps
:
import { route } from "nextjs-routes";
export const getServerSideProps: GetServerSideProps = async (context) => {
return {
redirect: {
destination: route({ pathname: "/foos/[foo]", query: { foo: "foobar" } }),
permanent: false,
},
};
};
Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.0.20...v0.0.21
Published by tatethurston about 2 years ago
chokidar
from devDependencies
to dependencies
so it's installed automatically.Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.0.19...v0.0.20
Published by tatethurston about 2 years ago
_error
, _app
, _document
). Thanks @JohnDaly for reporting.Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.0.18...v0.0.19
Published by tatethurston over 2 years ago
query
is now typed as string | string[] | undefined
instead of string | undefined
by @sachinraja.
nextjs-routes
can now be configured via your next.config.js
to automatically regenerate types whenever your routes change:
// next.config.js
/** @type {import('next').NextConfig} */
const { withRoutes } = require("nextjs-routes/next-config.cjs");
const nextConfig = {
reactStrictMode: true,
};
module.exports = withRoutes(nextConfig);
This wiring will only run in Next.js' development server (eg npx next dev
) and withRoutes
will no-op in production.
Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.0.17...v0.0.18
Published by tatethurston over 2 years ago
next/link
and next/router
by @sachinraja._
. _app
, _document
, _error
and middleware
are excluded.Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.0.16...v0.0.17
Published by tatethurston over 2 years ago
Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.0.15...v0.0.16
Published by tatethurston over 2 years ago
Route
was available globally. Now, it must be imported:import type { Route } from "nextjs-routes";
useRouter
is now correctly typed as string | undefined
instead of string
. If you know the current route, you can supply a type argument to narrow required parameters to string, eg: // if you have a page /foos/[foo].ts
const router = useRouter<"/foos/[foo]">();
// foo will be typed as a string, because the foo query parameter is required and thus will always be present.
const { foo } = router.query;
Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.0.14...v0.0.15
Published by tatethurston over 2 years ago
Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.0.13...v0.0.14
Published by tatethurston over 2 years ago
Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.0.12...v0.0.13
Published by tatethurston over 2 years ago
next/link
and next/router
.This means replacing imports of next/link
with nextjs-routes/link
and next/router
with nextjs-routes/router
is no longer necessary:
-import Link from "nextjs-routes/link";
+import Link from "next/link";
-import { useRouter } from 'nextjs-routes/router'
+import { useRouter } from 'next/router'
Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.0.11...v0.0.12
Published by tatethurston over 2 years ago
Published by tatethurston over 2 years ago
Full Changelog: https://github.com/tatethurston/nextjs-routes/compare/v0.0.9...v0.0.10