Next.js Discord

Discord Forum

Trying to make router.push work (beginner)

Answered
Minskin posted this in #help-forum
Open in Discord
MinskinOP
Hello, friends,

I'm desperately trying to get my nextjs router to take me to a page I created.

My page is in app/pages/ArticlePage.tsx

export function ArticlePage() {
  return (...)
}


And so I want this button from my main page.tsx to redirect to the Article page

      <button className="..."
        onClick={() => router.push("/article")}>
        Access the resources
      </button>


but I have a 404 error, page not found :/

How to fix this ? thank you
Answered by Minskin
I made it works by putting the pages folder in the app directory and not in app/src
View full answer

8 Replies

Siberian
I'd recommend you read through the docs on routing and such
the issues here are that routes are defined by folder names, and if you want them to have a Page you need to add a page.tsx (filename needs to be Page), That would be app/pages/article/page.tsx in this case.
also that page needs to default export a react component
so export default function instead of export function
MinskinOP
I made it works by putting the pages folder in the app directory and not in app/src
Answer
Siberian
ooh sorry yea I thought you wanted to have /pages/article as an URL, if you want to use the pages router it does indeed need to be in the same directory as app (so either root or src)