Migrating from 4.0.0

This section outlines the breaking changes introduced since version 4 of Astro Typesafe Routes. Review the details below to ensure a smooth upgrade.


Astro 4

Support for Astro ^4.0.0 has been dropped. Please upgrade to ^5.0.0 to stay compatible.


Reading Params

Getting typed params now use createRoute and Route.getParams instead.

const { id } = getParams(Astro, "/[id]");

Replace with:

const Route = createRoute({
  routeId: "/blog/[id]",
});

const { id } = Route.getParams(Astro);

Search Schema

The search schema is now declared inside createRoute.

export const searchSchema = z.object({ limit: z.number() });

Replace with:

export const Route = createRoute({
  routeId: "/",
  searchSchema: z.object({ limit: z.number() }),
});

Reading Search Params

Typed search params are now accessed from Route.getSearch.

const search = getSearch(Astro, searchSchema);

Replace with:

const search = Route.getSearch(Astro);

Route Type

The type Route has been renamed to RouteId.

import { Route } from "astro-typesafe-routes/path";

Replace with:

import { RouteId } from "astro-typesafe-routes/path";

Spread params

Spread params are now passed without the ... prefix.

<Link to="/blog/[...path]" params={{ "...path": "about" }}>
  Blog
</Link>

Replace with:

<Link to="/blog/[...path]" params={{ path: "about" }}>
  Blog
</Link>