Skip to content

Using redirect function on frontend results in JS error #16143

@KieranP

Description

@KieranP

Describe the bug

Using sveltekit redirect does not work on client side. Results in JS error:

Uncaught 
Object { status: 303, location: "/clients/new" }
​
location: "/clients/new"
​
status: 303
​
<prototype>: Object { … }
[events.js:276:3](http://localhost:5173/node_modules/svelte/src/internal/client/dom/elements/events.js)
    handle_event_propagation events.js:276
    (Async: EventListener.handleEvent)
    event_handle render.js:186
    _mount render.js:201
    hydrate render.js:123
    Svelte4Component legacy-client.js:113
    <anonymous> legacy-client.js:52
    initialize client.js:480
    _hydrate client.js:2663
    InterpretGeneratorResume self-hosted:1425
    AsyncFunctionNext self-hosted:800
    (Async: async)
    start client.js:325
    AsyncFunctionNext self-hosted:800
    (Async: async)
    <anonymous> (index):13460
    (Async: promise callback)
    <anonymous>

Would be nice if I could use redirect over window.location, so that it is consistent throughout codebase. For now, I'll fallback to window.location instead.

Reproduction

<script type="ts">
  import { redirect } from '@sveltejs/kit'

  function onclick() {
    redirect(303, '/clients/new')
  }
</script>

<button
  {onclick}
  type="button"
>
  Redirect Me
</button>

Logs

System Info

System:
    OS: macOS 15.5
    CPU: (12) arm64 Apple M3 Pro
    Memory: 92.17 MB / 18.00 GB
    Shell: 5.9 - /opt/homebrew/bin/zsh
  Binaries:
    Node: 23.10.0 - ~/.asdf/installs/nodejs/23.10.0/bin/node
    Yarn: 4.9.2 - ~/.asdf/installs/nodejs/23.10.0/bin/yarn
    npm: 10.9.2 - ~/.asdf/plugins/nodejs/shims/npm
    bun: 1.2.16 - /opt/homebrew/bin/bun
  Browsers:
    Safari: 18.5
  npmPackages:
    svelte: ^5.34.1 => 5.34.1

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions