Redirect with Slim 4

How can I achieve the same result in Slim 4? This was my slim 3 code. Is there such thing as $response->withRedirect in slim 4? I couldn’t find anything in documentation.
return $response->withRedirect($this->router->pathFor('MyPage'));

https://www.slimframework.com/docs/v4/objects/response.html#returning-a-redirect

return $response
  ->withHeader('Location', 'https://www.example.com')
  ->withStatus(302);

To create a redirect by a given route name:

use Slim\Routing\RouteContext;

$routeParser = RouteContext::fromRequest($request)->getRouteParser();
$url = $routeParser->urlFor('MyPage');

return $response
  ->withHeader('Location', $url)
  ->withStatus(302);