Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How To Stop Link Component From Giving 404 Error in NextJS?

Can anyone tell me why the following Link Component is unable to find the linked page? VSCode is literally auto-completing the file name as I type it in but for some reason I keep getting 404.

//index.js in WelcomePage folder
import styles from "/styles/WelcomePage.module.css";
import Link from "next/link";

function WelcomePage() {
  return (
    <>
      <h1 className={styles.title}>This is the Title</h1>
      <Link href="/pages/ClassSearch">Class Search</Link>
    </>
  );
}

export default WelcomePage;
//index.js in ClassSearch folder
function ClassSearch() {
  return <h1>The Class Search Page</h1>;
}

export default ClassSearch;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I think you need to link /ClassSearch instead of pages/ClassSearch

If you create pages/ClassSearch/index.js that exports a React component ,
it will be accessible at /ClassSearch

// <Link href="/pages/ClassSearch">Class Search</Link>
<Link href="/ClassSearch">Class Search</Link>

You can check , Next Page Doc

https://nextjs.org/docs/basic-features/pages

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading