From 23721d1fbed04083069f07c068289282819ff4cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gautier=20Ben=20A=C3=AFm?= <48261497+GauBen@users.noreply.github.com> Date: Sat, 19 Aug 2023 23:44:16 +0200 Subject: [PATCH] feat: accept `URL` in `redirect` (#10570) Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> --- .changeset/shy-turtles-fail.md | 5 +++++ packages/kit/src/exports/index.js | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/shy-turtles-fail.md diff --git a/.changeset/shy-turtles-fail.md b/.changeset/shy-turtles-fail.md new file mode 100644 index 000000000000..b0f4c3ccf402 --- /dev/null +++ b/.changeset/shy-turtles-fail.md @@ -0,0 +1,5 @@ +--- +"@sveltejs/kit": minor +--- + +feat: accept `URL` in `redirect` diff --git a/packages/kit/src/exports/index.js b/packages/kit/src/exports/index.js index cfe942f8d6ce..7be910b8074d 100644 --- a/packages/kit/src/exports/index.js +++ b/packages/kit/src/exports/index.js @@ -38,14 +38,14 @@ export function error(status, body) { * Create a `Redirect` object. If thrown during request handling, SvelteKit will return a redirect response. * Make sure you're not catching the thrown redirect, which would prevent SvelteKit from handling it. * @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages). Must be in the range 300-308. - * @param {string} location The location to redirect to. + * @param {string | URL} location The location to redirect to. */ export function redirect(status, location) { if ((!BROWSER || DEV) && (isNaN(status) || status < 300 || status > 308)) { throw new Error('Invalid status code'); } - return new Redirect(status, location); + return new Redirect(status, location.toString()); } /**