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

NextJS dynamic routes not working on my localhost

src/app/user/[username].js

[username].js file:

import { useRouter } from 'next/router'

export default function User() {
  const router = useRouter()
  return (
    <p>
      {router.query.username}
    </p>
  );
}

When i go to "localhost:3000/user/john" user/username url returning 404 not found.

enter image description here

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 followed the examples in the current documentation exactly, but I still get the 404 output.
https://nextjs.org/docs/pages/building-your-application/routing/dynamic-routes

>Solution :

The documentation for the App router states that your page should be at app/user/[username]/page.js instead of app/user/[username].js

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