Next.js Discord

Discord Forum

NEXT SSG show 404 Error

Unanswered
German Hound posted this in #help-forum
Open in Discord
German HoundOP
i have this games/[slug].jsx file i dont know everything seems fine but still i get 404 on single game
this is my API response
import axios from "axios";
import { apiurl } from "@/lib/apiConfig";
const apisecret = process.env.NEXT_PUBLIC_API_SECRET;

const GameDetailPage = ({ response }) => {
  return <div>{response}</div>;
};
export default GameDetailPage;

export async function getStaticPaths() {
  const response = await axios.get(`${apiurl}/api/games`, {
    headers: {
      Authorization: `Bearer ${apisecret}`,
    },
  });
  const gameparams = response.data.data;
  const paths = gameparams.map((game) => ({
    params: { slug: game.attributes.slug },
  }));
  return {
    paths,
    fallback: false,
  };
}
export async function getStaticProps({ params }) {
  try {
    const response = await axios.get(
      `${apiurl}/api/games?filters[slug][$eq]=${params.slug}&populate=%2A`,
      {
        headers: {
          Authorization: `Bearer ${apisecret}`,
        },
      }
    );
    return {
      props: {
        response,
      },
    };
  } catch (error) {
    console.error("Error fetching game data:", error);
    return {
      notFound: true,
    };
  }
}
and this is my API response

0 Replies