zilch / type-route

The flexible, type safe routing library.

Home Page:https://type-route.zilch.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enhancement Suggestion: Remove default query parameters automatically

garronej opened this issue · comments

Hello!

Firstly, I want to reiterate the expression of my gratitude for the excellent work on Type-route. It's been a vital part of our project in Onyxia, significantly enhancing our development experience.

I have a suggestion for an enhancement that we've been missing for a while now.

Here's an example to illustrate my point:

export const routeDefs = {
    "dataExplorer": defineRoute(
        {
            "source": param.query.optional.string,
            "rowsPerPage": param.query.optional.number.default(25),
            "page": param.query.optional.number.default(1)
        },
        () => `/data-explorer`
    )
};

Currently, when navigating to subsequent pages in a dataset, our approach is to call:

routes[route.name]({
    ...route.params,
    page: route.params.page + 1
}).replace()

This results in URLs such as:

https://an-onyxia-instance.net/data-explorer?source="..."&rowsPerPage=25&page=2

The issue here is the inclusion of rowsPerPage=25, which is the default value. Ideally, we would prefer such default parameters to be omitted from the URL to maintain simplicity and brevity.

If Type-route could automatically exclude parameters from the URL when they match their default values, it would be really nice. For example, turning long URLs like:

https://datalab.sspcloud.fr/data-explorer?source=https%3A%2F%2Fshell.duckdb.org%2Fdata%2Ftpch%2F0_01%2Fparquet%2Flineitem.parquet&rowsPerPage=25&page=1&selectedRow=4&columnWidths=%7B%7D&columnVisibility=%7B%7D

Into more concise versions:

https://datalab.sspcloud.fr/data-explorer?source=https%3A%2F%2Fshell.duckdb.org%2Fdata%2Ftpch%2F0_01%2Fparquet%2Flineitem.parquet&selectedRow=4

Your consideration of this suggestion is greatly appreciated. Thank you for your continued efforts in making Type-route a remarkable tool for developers.

Best regards,

I love this idea! In fact, I've encountered the exact same problem and have wanted to do something about it. However, I'm in the midst of building a nascent startup and don't have time to commit in the near future. I'd be happy to review a PR though!

Just released https://github.com/zilch/type-route/releases/tag/1.1.0. Thanks again for the contribution @garronej!