What's changed?
π New Features
π§© should_append_query Option
A new should_append_query
boolean flag has been introduced to control whether encoded query parameters are automatically appended to the generated link.
const route_config = {
products: {
path: "/products?order"
}
} as const satisfies RouteConfig;
const link = link_generator(route_config, { should_append_query: false });
link("products", undefined, { order: "asc" }); // => /products (no query string!)
π§ transform
Option
You can now customize link generation behavior by passing a transform
function to link_generator
.
- The
transform
function receives aRouteContext
object that provides detailed metadata about the current route, includingid
,path
,params
, andquery
. - It can return a custom
string
path, or returnundefined
to fall back to the defaultctx.path
. - This makes it easy to override only specific routes while preserving default behavior for the rest.
const link = link_generator(route_config, {
transform: (ctx) => {
const { id, path, params, query } = ctx;
if (id === "products" && query.order) {
return "/custom";
}
// fallback to ctx.path
},
should_append_query: false
});
link("products", undefined, { order: "asc" }); // => /custom
link("products"); // => /products (because no order query)
π Documentation
Added full documentation for transform and add_query under the Options section.
Examples included for conditional transforms and query parameter control.
This is especially useful in combination with transform, where you might want full control over the output path.