redirect method

Future<void> redirect(
  1. dynamic url, {
  2. bool absolute = true,
  3. int? code,
})

Redirects to user to the given URL.

url can be a String, or a List. If it is a List, a URI will be constructed based on the provided params.

See Router#navigate for more. :)

Implementation

Future<void> redirect(url, {bool absolute = true, int? code}) {
  if (!isOpen) throw closed();
  headers
    ..['content-type'] = 'text/html'
    ..['location'] = (url is String || url is Uri)
        ? url.toString()
        : app!.navigate(url as Iterable, absolute: absolute);
  statusCode = code ?? 302;
  write('''
  <!DOCTYPE html>
  <html>
    <head>
      <title>Redirecting...</title>
      <meta http-equiv="refresh" content="0; url=$url">
    </head>
    <body>
      <h1>Currently redirecting you...</h1>
      <br />
      Click <a href="$url">here</a> if you are not automatically redirected...
      <script>
        window.location = "$url";
      </script>
    </body>
  </html>
  ''');
  return close();
}