Skip to content

Commit

Permalink
feat: accept URL in redirect (#10570)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
  • Loading branch information
GauBen and benmccann authored Aug 19, 2023
1 parent 9e856c9 commit 23721d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-turtles-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": minor
---

feat: accept `URL` in `redirect`
4 changes: 2 additions & 2 deletions packages/kit/src/exports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit 23721d1

Please sign in to comment.