sveltejs / sveltejs/kit

Add ability to have multiple +page.svelte for one route

Open
#13,653 6 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the problem

Imagine a typical social media platform, where unauthenticated users are greeted with a marketing site with signup/login on the root path /.
After the user has logged in, the root path typically shows the feed.

If you want to implement this behavior in sveltekit, at the moment your only option is to use if blocks in the / +page.svelte to conditionally show the marketing signup/login page or the authenticated social feed. With this approach you basically mingle two pages into one file and loose the ability to have different layouts or load functions.

Describe the proposed solution

It would be a lot cleaner if these two pages would have separate +page.svelte files.

With the file based routing one of the two pages would have to be declared as a subpath for example the feed page would be located in a /feed/+page.svelte

Now we'd need some kind of server hook similar to the existing reroute to tell the sveltekit router that the feed page is not to be shown as /feed in the url bar but as / based on the user session state.
If you use goto('/feed') this should also trigger the hook and show the feed under the root path.

Alternatives considered

No response

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 with SvelteKit's file-based routing, the existing reroute hook, and goto navigation. Examine how /feed/+page.svelte and the root +page.svelte are resolved for different session states. Done should allow separate page files to render at / based on authentication without changing the URL, including navigation through goto.

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.