shredbx logo
shredbx shredbx shredbx shredbx Personal
  • Home
  • Lab
  • Portfolio
  • Experience
  • Services
  • Profile
  • Contact
AClaude
  • Home
  • Lab
  • Portfolio
  • Experience
  • Services
  • Profile
  • Contact
Andrei Solovev
Knowledge
Search knowledge... ⌘K
Knowledge · Guidelines · sveltekit

Sveltekit Routing Patterns

SvelteKit routing, server load functions, form actions, error handling, and layout patterns. Sourced from official SvelteKit documentation — enforced during FDD4.UI steps. Complements the sveltekit-server-load-pattern solution with broader routing coverage.

Andrei Solovev

Metadata

sveltekit sveltekit

Procedures

Showing 3 of 12

  1. SK.1 ALL data loading MUST happen in +page.server.ts load functions — NEVER in onMount or client-side fetch
    // +page.server.ts
    import type { PageServerLoad } from './$types';
    
    export const load: PageServerLoad = async ({ fetch, params }) => {
      const res = await fetch(`${API_BASE}/api/items/${params.id}`);
      if (!res.ok) throw error(res.status, 'Failed to load');
      return await res.json();
    };
  2. SK.2 Use the error() helper from @sveltejs/kit for HTTP error responses in load functions
    import { error } from '@sveltejs/kit';
    
    export const load: PageServerLoad = async ({ params }) => {
      const post = await getPost(params.slug);
      if (!post) error(404, { message: 'Not found' });
      return { post };
    };
  3. SK.3 Use redirect() helper for server-side redirects — NEVER client-side window.location
    import { redirect } from '@sveltejs/kit';
    
    export const load: LayoutServerLoad = ({ locals }) => {
      if (!locals.user) redirect(307, '/login');
    };
shredbx logo shredbx shredbx shredbx shredbx Andrei Solovev

Solution Architect & Lead Software Engineer

ExperiencePortfolioResearch & ExperimentsEducationCertificationSkills
GitHub ↗LinkedIn ↗Email ↗
AVAILABLE FOR NEW PROJECTS
// MY LATEST BEATS
Hobby & Interests

Lab

  • The Lab
  • Framework
  • Components
  • Packages
  • Games
  • Process (SDLC)
  • Knowledge
  • Blog

Andrei

  • Portfolio
  • Experience
  • Services
  • Profile
  • Contact
  • Lifestyle

Team

  • Team
  • Andrei
  • Claude

Legal

  • Privacy
  • Terms
  • Cookies
© 2026 shredbx.com. All rights reserved. — Andrei Solovev |