This function onTransformRouteUrl() allows you to change the route URL before it is sent to Atatus. This function takes original URL as a param and return modified URL.

copy
icon/buttons/copy
atatus.onTransformRouteUrl((url) => {
    // You can modify the route url
    return url;
});

Example

Transforms the URL:

  • Converts the URL string to a URL object to easily manipulate its components.
  • Replaces numeric segments in the path with :id, which is useful for standardizing URL paths in routes.
  • Moves the query parameter tab to the end of the path if it exists, formatting it as tab-{value}.
copy
icon/buttons/copy
if (atatus.onTransformRouteUrl) {
    atatus.onTransformRouteUrl((url) => {
        try {
            let urlObj = new URL(url);
            let path = urlObj.pathname;

            // Replace numeric segments with ':id'
            var numericRegex = /(\d+)(?=[\/?]|$)/g;
            path = path.replace(numericRegex, ':id');

            // Move query params to path.
            let queryParams = urlObj.searchParams;
            let formattedQuery = '';
            if (queryParams) {
                let tabParam = queryParams.get('tab');
                if (tabParam) {
                    formattedQuery = `${path.slice(-1) === '/' ? '' : '/'}tab-${tabParam}`;
                }
            }
            return `${urlObj.origin}${path}${formattedQuery}`;

        } catch(e) {}

        return url;
    });
}