sveltejs / sveltejs/kit

Forcing reload on +page.server redirects

Open
#12,626 7 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

I have a /login page which can either show a login form for local accounts, or hit an api server that handes oauth logins, depending on whether oauth was configured and the presence of a ?bypass_oauth=1 parameter.

Basically it goes like this:

  • link navigates to /login
  • oauth was configured: the load function of +page.server.ts redirects to https://API_DOMAIN/auth/oauth2
  • oauth was bypassed or not configured: the /login page is shown as usual

and in my use case, API_DOMAIN is actually the same as the frontend origin.

But when navigating from the client (so, not on the first page load), I get client-side navigated to /auth/oauth2.

Describe the proposed solution

An optional parameter on the Redirect object (not having it on the redirect convenience function is fine to me since the use case is pretty rare) that essentially does what data-sveltekit-reload does

maybe sth like

throw new Redirect(301, "Full URL", { reload: true })
Alternatives considered

Using <a data-svelkit-reload>, but it becomes hard to ensure all links anywhere that point to /login have the correct behavior - it kind of prevents encoding the required redirection logic in the load function itself. Using a <LoginLink> component can work but unfortunately not for everything - in some cases my app calls goto on /login

Using +server.ts - not really an option in my use case since I also have a +page.svelte

Importance

would make my life easier

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the +page.server.ts redirect flow and the Redirect object, then compare it with data-sveltekit-reload, +server.ts, +page.svelte, and goto as described in the issue. The change would be complete when a redirect can request a full reload for client-side navigation without requiring every link to use data-sveltekit-reload.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.