Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
Static Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamesh-mutkure committed Apr 23, 2024
1 parent 65f5ee7 commit ca48521
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions src/pages/[exerciseID].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,40 @@
import { useRouter } from "next/router";
import data from "@/data";
import Exercise from "@/components/exercise";
import exp from "constants";
import { TExerciseData } from "@/types";
import { GetStaticPathsContext, GetStaticPropsContext } from "next";

export default function ExercisePage() {
const router = useRouter();
const exerciseID = router.query.exerciseID as string;
export default function ExercisePage({
excercise,
}: {
excercise: TExerciseData;
}) {
// const router = useRouter();
// const exerciseID = router.query.exerciseID as string;

if (!exerciseID) return <div>Loading...</div>;
if (!Object.keys(data).includes(exerciseID)) router.push("/");
// if (!exerciseID) return <div>Loading...</div>;
// if (!Object.keys(data).includes(exerciseID)) router.push("/");

const exercise = data[exerciseID];
// const exercise = data[exerciseID];

return <Exercise data={exercise} />;
return <Exercise data={excercise} />;
}

export async function getStaticPaths(context: GetStaticPathsContext) {
return {
paths: Object.keys(data).map((exerciseID) => ({ params: { exerciseID } })),
fallback: false,
};
}

export async function getStaticProps(context: GetStaticPropsContext) {
const exerciseID = context.params?.exerciseID as string;
const excercise = data[exerciseID];

return {
props: {
excercise,
},
};
}

0 comments on commit ca48521

Please sign in to comment.