Documentation
    Preparing search index...

    Exposes the API to construct redirect routes

    Index

    Constructors

    • Creates a new Redirect instance for handling HTTP redirects

      Parameters

      • request: IncomingMessage

        Node.js incoming HTTP request

      • response: Response

        AdonisJS response instance

      • router: Router

        AdonisJS router instance

      • qs: Qs

        Query string parser instance

      Returns Redirect

    Methods

    • Sets a custom HTTP status code for the redirect response

      Parameters

      • statusCode: number

        HTTP status code to use (e.g., 301, 302, 307)

      Returns this

      The Redirect instance for method chaining

    • Clears any query string values previously added using the withQs method

      Returns this

      The Redirect instance for method chaining

    • Forwards the current request's query string to the redirect URL

      Use this overload when you want to preserve all existing query parameters from the current request in the redirect URL.

      Returns this

      The Redirect instance for method chaining

      // If current URL is '/search?q=hello&page=2'
      response.redirect().withQs().toPath('/results')
      // Redirects to: '/results?q=hello&page=2'
    • Adds multiple query string parameters to the redirect URL

      Use this overload when you want to add several query parameters at once using an object with key-value pairs.

      Parameters

      • values: Record<string, any>

        Object containing query parameter names and values

      Returns this

      The Redirect instance for method chaining

      response.redirect().withQs({ page: 1, sort: 'name' }).toPath('/users')
      // Redirects to: '/users?page=1&sort=name'
    • Adds a single query string parameter to the redirect URL

      Use this overload when you want to add just one query parameter with a specific name and value.

      Parameters

      • name: string

        The query parameter name

      • value: any

        The query parameter value

      Returns this

      The Redirect instance for method chaining

      response.redirect().withQs('success', 'true').toPath('/dashboard')
      // Redirects to: '/dashboard?success=true'
    • Redirects to the previous path using the Referer header Falls back to '/' if no referrer is found

      Returns void

    • Redirects to a route using its identifier (name, pattern, or handler reference)

      Type Parameters

      • Identifier extends string

      Parameters

      • ...args: []

        Route identifier, parameters, and options for URL building

      Returns void

    • Redirects to a specific URL path

      Parameters

      • url: string

        Target URL path for redirection

      Returns void