$request->getUri()->withPath() preserves URL parameters

I’m doing the following to redirect from a page which has some URL parameters:

return $response->withRedirect ((string)($request->getUri()->withPath($this->router->pathFor($routeName))));

This works in the sense that I’m being redirected to the desired page, but the URL parameters of the page are being preserved in the URL I’m being redirect to.

How can I redirect to a route-based URL without preserving the existing URL parameters (ie: just to a clean route URL)?

Thanks in advance

$uri->withQuery('')->withFragment('');

1 Like

Works like a charm, thank you very much!