Add query parameters on hook "panel.route:after"

Hi, how could i add new parameters on panel routes navigation?
I would like to open a specific tab on some routes.
Had no look with the :before hook too.

Here is what I tried:

Kirby::plugin('router/queries', [
	'hooks' => [
		'panel.route:after' => function (Route $route, string $path, mixed $response) {

			$query = http_build_query(array_merge($_GET, ['tab' => 'settings']));
			$path = $path . '?' . $query;

			// how to replace the route with new queries?

		},
	]
]);

I think you need a panel.route:before hook here, then use Panel::go() to redirect to the new location. Make sure to use conditions to make sure you can still reach other tabs.

Thanks, unfortunately this seems to create an infinite redirection loop. It crashes the navigation

'panel.route:before' => function (Route $route, string $path, mixed $response) {
	$query = http_build_query(array_merge($_GET, ['tag' => 'tools']));
	$path = $path . '?' . $query;

	Panel::go($path);

},

I tried to return the $route as stated in the doc. But I’m not sure how to edit it with the new query

Shouldn’t this be tab?

And as I said, you cannot use this code as is, otherwise, you won’t be able to ever access other tabs again.

Also make sure that this only affects the site or pages routes, not simply any route.

Thanks for the quick reply.
It’s tab yes

Here is my code, with some custom methods.

'panel.route:before' => function (Route $route, string $path, mixed $response) {

	$targetPage = findPage($path);  // custom function

	if (!$targetPage)
		return;
	if ($targetPage->intendedTemplate() != 'product')
		return;

	$originPath = Panel::referrer();
	if (!$originPath)
		return;

	if (!matchPage($originPath, 'page://notices')) // custom function
		return;

	$query = http_build_query(array_merge($_GET, ['tab' => '123']));
	$path = $path . '?' . $query;

	// return route with added query ?
},

Temporary solution, in a js plugin

window.addEventListener('load', () => {
    const view = window.panel.$view;

    window.Vue.watch(() => view.props.blueprint, (newVal, oldVal) => {
        const noticeToProduct = oldVal === 'notices' && newVal === 'product'
        if (!noticeToProduct) return;

        const url = new URL(window.location.href);
        url.searchParams.set('tab', 'infos');
        window.history.replaceState({}, '', url.href);
        view.refresh({ url: url.href });
    });
})