Skip to content

v9.1.0

Latest
Compare
Choose a tag to compare
@cat394 cat394 released this 27 Jul 06:06
· 8 commits to main since this release

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 a RouteContext object that provides detailed metadata about the current route, including id, path, params, and query.
  • It can return a custom string path, or return undefined to fall back to the default ctx.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.