-
Notifications
You must be signed in to change notification settings - Fork 27.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong page when navigating from pages router to app router #74696
Comments
This appears to be a bug or unintended behavior in the Next.js routing system when transitioning from the pages directory to the app directory. The issue lies in the mismatch between dynamic routes in the pages and app directories and how the router prioritizes them. Analysis of the Issue
When navigating programmatically (via href="/hello"), the router appears to prioritize the pages/[...slug].js route over app/[lang]/page.js. However, refreshing the page correctly resolves to app/[lang]/page.js.
Possible Causes
Potential Workarounds
i would recommend you to move one of you your pages (either under app route or page route ) to one level down so that there will be no routes conflicts example bellow Pages Route
App Route
Note:If your app is public and you're concerned about losing your SEO rankings or breaking backlinks, here's what you should do:
By planning strategically and using redirections effectively, you can maintain your SEO integrity and avoid link breakage issues. |
Link to the code that reproduces this issue
https://github.com/pomber/bug-pages-router-to-app-router
To Reproduce
In this app:
npm run dev
localhost:3000
click theGo to App router
link (href="/hello"
)Current vs. Expected behavior
It renders
pages/[...slug].js
instead of renderingapp/[lang]/page.js
.If instead we refresh the page with the same URL (
localhost:3000/hello
) it rendersapp/[lang]/page.js
as expected.Provide environment information
Which area(s) are affected? (Select all that apply)
Navigation
Which stage(s) are affected? (Select all that apply)
next dev (local), next start (local)
Additional context
No response
The text was updated successfully, but these errors were encountered: