bug修复
This commit is contained in:
1 parent
4dfce9b521
commit
75f67bf08c
7 files changed
+67
-19
No files matched your search
+15
-10
@@ -165,6 +165,7 @@ function usePageSeo(pageType: string, targetCode = "") {
|
||||
}, [pageType, targetCode]);
|
||||
}
|
||||
const nav = [
|
||||
["Home", "/"],
|
||||
["Products", "/products"],
|
||||
["Cases", "/cases"],
|
||||
["News", "/news"],
|
||||
@@ -193,11 +194,13 @@ function NavigationLinks({ items }: { items: NavigationItem[] }) {
|
||||
}
|
||||
function route() {
|
||||
const p = location.pathname.split("/").filter(Boolean);
|
||||
const previewPage = new URLSearchParams(location.search).get("previewPage") || undefined;
|
||||
if (!p.length) return { kind: "home", previewPage };
|
||||
const parameters = new URLSearchParams(location.search);
|
||||
const previewPage = parameters.get("previewPage") || undefined;
|
||||
const categoryCode = parameters.get("category") || undefined;
|
||||
if (!p.length) return { kind: "home", previewPage, categoryCode };
|
||||
if (["products", "news", "cases", "help"].includes(p[0]))
|
||||
return { kind: p[0], slug: p[1], previewPage };
|
||||
return { kind: "page", slug: p[0], previewPage };
|
||||
return { kind: p[0], slug: p[1], previewPage, categoryCode };
|
||||
return { kind: "page", slug: p[0], previewPage, categoryCode };
|
||||
}
|
||||
function App() {
|
||||
const r = route();
|
||||
@@ -212,10 +215,10 @@ function App() {
|
||||
const runtime = <CustomCodeRuntime />;
|
||||
const seoRuntime = <SeoRuntime current={r} />;
|
||||
if (r.kind === "home") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || "HOME"} fallback={<><Header /><main><Home /></main><Footer /></>} /></>;
|
||||
if (r.kind === "products") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug ? "PRODUCT_DETAIL" : "PRODUCT_CATEGORY")} fallback={<><Header /><main><Collection title="Products" type="products" slug={r.slug} /></main><Footer /></>} /></>;
|
||||
if (r.kind === "news") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug ? "NEWS_DETAIL" : "NEWS_CATEGORY")} fallback={<><Header /><main><Collection title="News" type="NEWS" slug={r.slug} /></main><Footer /></>} /></>;
|
||||
if (r.kind === "cases") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug ? "CASE_DETAIL" : "CASE_CATEGORY")} fallback={<><Header /><main><Collection title="Case Studies" type="CASE" slug={r.slug} /></main><Footer /></>} /></>;
|
||||
if (r.kind === "help") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug ? "HELP_DETAIL" : "HELP_CATEGORY")} fallback={<><Header /><main><Collection title="Help Center" type="HELP" slug={r.slug} /></main><Footer /></>} /></>;
|
||||
if (r.kind === "products") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug ? "PRODUCT_DETAIL" : "PRODUCT_CATEGORY")} fallback={<><Header /><main><Collection title="Products" type="products" slug={r.slug} categoryCode={r.categoryCode} /></main><Footer /></>} /></>;
|
||||
if (r.kind === "news") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug ? "NEWS_DETAIL" : "NEWS_CATEGORY")} fallback={<><Header /><main><Collection title="News" type="NEWS" slug={r.slug} categoryCode={r.categoryCode} /></main><Footer /></>} /></>;
|
||||
if (r.kind === "cases") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug ? "CASE_DETAIL" : "CASE_CATEGORY")} fallback={<><Header /><main><Collection title="Case Studies" type="CASE" slug={r.slug} categoryCode={r.categoryCode} /></main><Footer /></>} /></>;
|
||||
if (r.kind === "help") return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug ? "HELP_DETAIL" : "HELP_CATEGORY")} fallback={<><Header /><main><Collection title="Help Center" type="HELP" slug={r.slug} categoryCode={r.categoryCode} /></main><Footer /></>} /></>;
|
||||
return <>{runtime}{seoRuntime}<DecoratedPage pageType={r.previewPage || (r.slug === "about-us" ? "ABOUT_US" : "CUSTOM_PAGE")} fallback={<><Header /><main><Page slug={r.slug!} /></main><Footer /></>} /></>;
|
||||
}
|
||||
function SeoRuntime({ current }: { current: ReturnType<typeof route> }) {
|
||||
@@ -376,10 +379,12 @@ function Collection({
|
||||
title,
|
||||
type,
|
||||
slug,
|
||||
categoryCode,
|
||||
}: {
|
||||
title: string;
|
||||
type: "products" | ContentType;
|
||||
slug?: string;
|
||||
categoryCode?: string;
|
||||
}) {
|
||||
const [data, setData] = useState<Item[] | Record<string, unknown>>([]);
|
||||
const [error, setError] = useState("");
|
||||
@@ -396,7 +401,7 @@ function Collection({
|
||||
} else {
|
||||
const x = await post(
|
||||
type === "products" ? "/products/list" : "/contents/list",
|
||||
type === "products" ? {} : { contentType: type },
|
||||
type === "products" ? { categoryCode } : { contentType: type, categoryCode },
|
||||
);
|
||||
setData(x.items || []);
|
||||
}
|
||||
@@ -405,7 +410,7 @@ function Collection({
|
||||
}
|
||||
};
|
||||
void run();
|
||||
}, [type, slug]);
|
||||
}, [type, slug, categoryCode]);
|
||||
if (error) return <ErrorState message={error} />;
|
||||
if (slug && !Array.isArray(data)) {
|
||||
const d = data as Record<string, any>;
|
||||
|
||||
Reference in new issue
Block a user