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
Returns
A response that redirects the client to the specified location
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.