fix: use dynamic recipeLang in API calls instead of hardcoded /api/rezepte

Client-side navigation to /recipes hung because getUserFavorites and
other endpoints were hardcoded to /api/rezepte, causing fetch mismatches
during SvelteKit's client-side routing.
This commit is contained in:
2026-04-07 19:50:34 +02:00
parent e59947dd97
commit 35721237b4
14 changed files with 23 additions and 19 deletions
+4 -1
View File
@@ -1,9 +1,12 @@
<script lang="ts">
import { browser } from '$app/environment';
import { enhance } from '$app/forms';
import { page } from '$app/stores';
let { recipeId, isFavorite = $bindable(false), isLoggedIn = false } = $props<{ recipeId: string, isFavorite?: boolean, isLoggedIn?: boolean }>();
const recipeLang = $derived($page.url.pathname.split('/')[1] || 'rezepte');
let isLoading = $state(false);
async function toggleFavorite(event: Event) {
@@ -17,7 +20,7 @@
try {
const method = isFavorite ? 'DELETE' : 'POST';
const response = await fetch('/api/rezepte/favorites', {
const response = await fetch(`/api/${recipeLang}/favorites`, {
method,
headers: {
'Content-Type': 'application/json',
+1 -1
View File
@@ -284,7 +284,7 @@
const apiBase = `/api/${isEnglish ? 'recipes' : 'rezepte'}`;
const [tagsRes, iconsRes] = await Promise.all([
fetch(`${apiBase}/items/tag`),
fetch('/api/rezepte/items/icon')
fetch(`${apiBase}/items/icon`)
]);
availableTags = await tagsRes.json();
availableIcons = await iconsRes.json();