skip to Main Content
src/app/user/.js
.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

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

2

Answers


  1. You have to put your page file in the pages folder.

    Route Example URL Params
    pages/[username].js /abdullah { username: ‘abdullah’ }
    Login or Signup to reply.
  2. The documentation for the App router states that your page should be at app/user/[username]/page.js instead of app/user/[username].js

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search