Kartica s targetUrl preusmeri tudi pri kliku znotraj strani (SPA)
This commit is contained in:
parent
8bf90c6942
commit
590e5438d3
@ -1,5 +1,5 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { useParams, Link } from "wouter";
|
import { useParams, Link, useLocation } from "wouter";
|
||||||
import { type Article } from "@shared/schema";
|
import { type Article } from "@shared/schema";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { de } from "date-fns/locale";
|
import { de } from "date-fns/locale";
|
||||||
@ -101,10 +101,18 @@ export default function ArticlePage() {
|
|||||||
const { slug } = useParams<{ slug: string }>();
|
const { slug } = useParams<{ slug: string }>();
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
|
|
||||||
|
const [, navigate] = useLocation();
|
||||||
|
|
||||||
const { data: article, isLoading, error } = useQuery<Article>({
|
const { data: article, isLoading, error } = useQuery<Article>({
|
||||||
queryKey: ["/api/articles", slug],
|
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 articleUrl = article ? `${window.location.origin}/article/${article.slug}` : "";
|
||||||
const articleImage = article?.coverImage
|
const articleImage = article?.coverImage
|
||||||
? (article.coverImage.startsWith("http") ? article.coverImage : `${window.location.origin}${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) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-background">
|
<div className="min-h-screen bg-background">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user