Skip to content

Instance Method

redirect(to:redirectType:)

Creates a redirect Response.
func redirect(to location: String, redirectType: Redirect = .normal) -> Response

Parameters

location

The path to redirect to

redirectType

The type of redirect to perform

Return Value

A response that redirects the client to the specified location

Discussion

router.get("redirect") { req in
    return req.redirect(to: "https://vapor.codes")
}

Set type to ‘.permanently’ to allow caching to automatically redirect from browsers. Defaulting to non-permanent to prevent unexpected caching.