Kartica s targetUrl preusmeri tudi pri kliku znotraj strani (SPA)

This commit is contained in:
sebastjan 2026-08-15 18:04:42 +02:00
parent 8bf90c6942
commit 590e5438d3

View File

@ -1,5 +1,5 @@
import { useQuery } from "@tanstack/react-query";
import { useParams, Link } from "wouter";
import { useParams, Link, useLocation } from "wouter";
import { type Article } from "@shared/schema";
import { format } from "date-fns";
import { de } from "date-fns/locale";
@ -101,10 +101,18 @@ export default function ArticlePage() {
const { slug } = useParams<{ slug: string }>();
const isMobile = useIsMobile();
const [, navigate] = useLocation();
const { data: article, isLoading, error } = useQuery<Article>({
queryKey: ["/api/articles", slug],
});
// Kartice (horoskop, recept) samo napotijo naprej — tudi pri kliku znotraj strani.
const targetUrl = (article as any)?.targetUrl as string | undefined;
useEffect(() => {
if (targetUrl) navigate(targetUrl, { replace: true });
}, [targetUrl, navigate]);
const articleUrl = article ? `${window.location.origin}/article/${article.slug}` : "";
const articleImage = article?.coverImage
? (article.coverImage.startsWith("http") ? article.coverImage : `${window.location.origin}${article.coverImage}`)
@ -262,6 +270,8 @@ export default function ArticlePage() {
if (targetUrl) return null;
if (isLoading) {
return (
<div className="min-h-screen bg-background">