NAME

PAGI::App::Redirect - URL redirect app for the dynamic case

SYNOPSIS

# The static case is just a response value (preferred):
use PAGI::Response;
$router->mount('/old' => PAGI::Response->redirect('/new', 301));

# PAGI::App::Redirect is for the dynamic case — a coderef target
# and/or query-string preservation:
use PAGI::App::Redirect;
my $app = PAGI::App::Redirect->new(
    to             => sub { my ($scope) = @_; compute_target($scope) },
    status         => 302,
    preserve_query => 1,
)->to_app;

DESCRIPTION

Performs HTTP redirects where the target is computed per request or query-string preservation is required. For a fixed target with no query-string handling, prefer "redirect" in PAGI::Response directly:

PAGI::Response->redirect('/new', 301);

Use this module when the redirect target is a coderef that receives $scope and returns the URL at request time, or when you need the preserve_query option to automatically append the incoming query string to the redirect target.

OPTIONS

  • to - Target URL (string or coderef receiving $scope)

  • status - HTTP status code (default: 302)

  • preserve_query - Append query string to target (default: 1)