Next.js Discord

Discord Forum

Request for Help: Link Redirection Leads to 404 Error

Unanswered
Bigeye tuna posted this in #help-forum
Open in Discord
Bigeye tunaOP
Dear Developer Community,

I hope you are having a pleasant coding day. I am currently facing a puzzling issue with page routing in my React project and am seeking your assistance.

I have two tsx files in my project: page.tsx and test.tsx. In page.tsx, I am using the <Link> component to create a hyperlink pointing to "/layout", as shown below:

jsx
Copy code
// /app/page.tsx:
<Link href="/layout" legacyBehavior>
<a>jump~~~</a>
</Link>
In test.tsx, I have a simple React component designed to display some text content, as follows:

jsx
Copy code
// /app/test.tsx:
import React from 'react';

const test = () => {
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<h1 className="text-4xl font-semibold mb-8">YEEEEEE</h1>
</main>
);
};

export default test;
The issue I'm encountering is that when I click on the link in the page component, I expect to navigate to the test component, but instead, I am greeted with a 404 not found error. I have checked my routing configurations but still can't pinpoint the cause of the issue.

Could you please assist me in determining why this error occurs? I suspect there might be a detail I'm missing in the link setup or routing configuration.

Thank you very much for your time and assistance!

Best regards,
Jeffrey

15 Replies

Bigeye tunaOP
up
if you want the href is /layout, the test component need to be in app/layout/page.tsx
@Ray please read the doc https://nextjs.org/docs/app/building-your-application/routing/defining-routes
Bigeye tunaOP
its my wrong,it should be
"<Link href="/test" legacyBehavior>
<a>jump~~~</a>
</Link>"
I want to test page jump but it doesn't work,always 404 not found
ok so create that component in app/test/page.tsx
move app/test.tsx to app/test/page.tsx
@Ray move app/test.tsx to app/test/page.tsx
Bigeye tunaOP
thanks! let me try it
@Ray ok so create that component in app/test/page.tsx
Bigeye tunaOP
I'm so sad that also doesn't work.This my project screenshot.
the href is /test and not /test/page
Bigeye tunaOP
you want the href to be /test right?
if you want the href to be /test/page, you need to create the component in app/test/page/page.tsx
Bigeye tunaOP
ohhhhhhh! it works! thank you very much
you should read the doc
@Ray you should read the doc
Bigeye tunaOP
yes i will read it again