From 940b198003b79efc10a251437dd9ad4b2a3fb193 Mon Sep 17 00:00:00 2001 From: s8613 Date: Sat, 14 Jun 2025 13:01:44 +0200 Subject: [PATCH] Fixed redirect when error. --- .../src/routes/extractedResult.$pitchBook.tsx | 14 +++++++++++--- .../routes/extractedResult_.$pitchBook.$kpi.tsx | 12 ++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/project/frontend/src/routes/extractedResult.$pitchBook.tsx b/project/frontend/src/routes/extractedResult.$pitchBook.tsx index feba82f..68acdb4 100644 --- a/project/frontend/src/routes/extractedResult.$pitchBook.tsx +++ b/project/frontend/src/routes/extractedResult.$pitchBook.tsx @@ -7,6 +7,7 @@ import { useState } from "react"; import KennzahlenTable from "../components/KennzahlenTable"; import PDFViewer from "../components/pdfViewer"; import { kpiQueryOptions, settingsQueryOptions } from "../util/query"; +import { redirect } from "@tanstack/react-router"; export const Route = createFileRoute("/extractedResult/$pitchBook")({ component: ExtractedResultsPage, @@ -15,11 +16,18 @@ export const Route = createFileRoute("/extractedResult/$pitchBook")({ from: search.from as string | undefined, }; }, - loader: ({ context: { queryClient }, params: { pitchBook } }) => - Promise.allSettled([ + loader: async ({ context: { queryClient }, params: { pitchBook } }) => { + const results = await Promise.allSettled([ queryClient.ensureQueryData(kpiQueryOptions(pitchBook)), queryClient.ensureQueryData(settingsQueryOptions()), - ]), + ]); + if (results[0].status === "rejected") { + throw redirect({ + to: "/" + }); + } + return results; + } }); function ExtractedResultsPage() { diff --git a/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx b/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx index ccf34b8..21dc929 100644 --- a/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx +++ b/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx @@ -23,11 +23,19 @@ import PDFViewer from "../components/pdfViewer"; import { kpiQueryOptions } from "../util/query"; import ArrowBackIcon from "@mui/icons-material/ArrowBack"; import {fetchPutKPI} from "../util/api"; +import { redirect } from "@tanstack/react-router"; export const Route = createFileRoute("/extractedResult_/$pitchBook/$kpi")({ component: ExtractedResultsPage, - loader: ({ context: { queryClient }, params: { pitchBook } }) => - queryClient.ensureQueryData(kpiQueryOptions(pitchBook)), + loader: async ({ context: { queryClient }, params: { pitchBook } }) => { + try { + return await queryClient.ensureQueryData(kpiQueryOptions(pitchBook)); + } catch (err) { + throw redirect({ + to: "/" + }); + } + }, }); function ExtractedResultsPage() {