NuxtN
Nuxt12mo ago
23 replies
Dog

[closed] Page appearing empty when navigating (but not directly)

On my website, https://nuxt.whitecoastrailway.com, clicking on News and Jobs in the navigation return pages with no actual content, only the header and footer (which itself is covered by the header).

I'm using Sanity with the official module as my CMS to display news posts and job listings, and almost the same code is used is used on each index page. Here's the script in the jobs page: (bit messy but idc)

import type { SanityDocument } from "@sanity/client";
const router = useRouter();

const JOBS_QUERY = groq`*[
  _type == "job"
  && defined(slug.current)
]|order(title, description)[0...12]{_id, title, description, department, open, slug}`;

const { data: jobs } = await useSanityQuery<SanityDocument[]>(JOBS_QUERY);

const results = ref<SanityDocument[] | null>(jobs.value ?? null);
const search = ref(decodeURIComponent(useRoute().query.search as string || ''));

watch(search, () => {
    if (search.value) {
        router.push({ query: { search: search.value } });
    } else {
        router.push({ query: {} });
    }
});

const handleSearch = () => {
    results.value = jobs.value?.filter((job) =>
        Object.values(job).some((value) => value.toString().toLowerCase().includes(search.value.toLowerCase()))
    ) || [];
};
Was this page helpful?