Skip to content

Commit

Permalink
404 page handling
Browse files Browse the repository at this point in the history
  • Loading branch information
PranjalMaithani committed Apr 26, 2021
1 parent d05bcb4 commit 8a42d37
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pages/guns/[slug].js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import GunPage from '../../components/GunPage';
import { getClient, usePreviewSubscription } from '../../utils/sanity';
import { groq } from 'next-sanity';
import Error from 'next/error';

const query = groq`*[_type == "gun" && slug.current == $slug][0]{..., country->, caliber->}`;

Expand All @@ -11,6 +12,10 @@ const Gun = ({ gunData, preview, slug }) => {
enabled: preview,
});

if (!gunData?.slug) {
return <Error statusCode={404} />;
}

if (liveData.loading) {
return <p>Loading Gun...</p>;
}
Expand Down Expand Up @@ -38,7 +43,7 @@ export async function getStaticPaths() {

return {
paths: paths.map((slug) => ({ params: { slug } })),
fallback: 'blocking',
fallback: false,
};
}

Expand Down

1 comment on commit 8a42d37

@vercel
Copy link

@vercel vercel bot commented on 8a42d37 Apr 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.