Next.js Discord

Discord Forum

Beginner Question: Server side rendering not working

Unanswered
Peterbald posted this in #help-forum
Open in Discord
PeterbaldOP
export default function Home({ message }) {
    return (
        <div>
            <h1>This is Home Page</h1>
            <h2>{message}</h2>
        </div>
    );
}

export function getServerSideProps() {
    return {
        notFound: true
    };
}


This returns the content, but not the server side not found page
I have also used another example and did this not work eitheer

11 Replies

Giant panda
Is your page file in the pages or the app folder?
If you are having that code in the app folder/router it won't work since the app router works entirely different. getServerSideProps is a construct of the pages router.
PeterbaldOP
its in app/ssr/page.tsx
what should i do instead
Giant panda
React Server Components work entirely different and you can call the notFound() function in the page component directly
export default function Home() {
  if (...) {
    notFound()
  }
  return ...
}
PeterbaldOP
so do i put this file somewhere else?
Giant panda
No, my point is that within the app dir you interact differently and gSSP is not a thing
PeterbaldOP
how do I use gSSP then
Giant panda
If you want to 404 just by calling notFound as I've shown, otherwise you just fetch data directly and asynchronously