Skip to content
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

next/link from pages to appDir url results in 404 #42513

Closed
1 task done
captbaritone opened this issue Nov 5, 2022 · 7 comments · Fixed by #43188
Closed
1 task done

next/link from pages to appDir url results in 404 #42513

captbaritone opened this issue Nov 5, 2022 · 7 comments · Fixed by #43188
Assignees
Labels
bug Issue was opened via the bug report template. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@captbaritone
Copy link

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.7.0
      npm: 8.15.0
      Yarn: 1.22.19
      pnpm: 6.34.0
    Relevant packages:
      next: 13.0.3-canary.0
      eslint-config-next: 13.0.0
      react: 18.2.0
      react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

next build; next start

Describe the Bug

I have a link from a page (old stye) which uses next/link and it points to a page defined using app dir. When I click the link in dev mode it works fine, but when I click the link using next build; next start I get a 404 page. Loading the URL via a link from within the app dir pages (using next/navigation's Link) works fine. Loading the URL directly (no client-side navigation) also works.

Expected Behavior

Clicking the link in the legacy part of my app opens the new page.

8ff964e89c6b34adc60b63be91a3570197c26d0e

Link to reproduction

https://github.com/captbaritone/jordaneldredge.com/

To Reproduce

Check out the repo, checkout hash 8ff964e89c6b34adc60b63be91a3570197c26d0e.

yarn
yarn build
yarn start

Click "Notes" in the nav bar.

Expected

Notes page loads

Actual

404 page renders

@captbaritone captbaritone added the bug Issue was opened via the bug report template. label Nov 5, 2022
@balazsorban44 balazsorban44 added Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. area: app labels Nov 6, 2022
@balazsorban44
Copy link
Member

balazsorban44 commented Nov 6, 2022

This might be related to the fact that trailingSlash: true is not yet supported as per the docs: https://beta.nextjs.org/docs/app-directory-roadmap#planned-features.

Although I tried to create a minimal reproduction but it works fine: https://github.com/balazsorban44/nextjs-42513

Could you narrow down the reproduction so I can easily clone/build it? Currently, it requires some API keys for Notion, but it would be beneficial to cut down everything irrelevant for the reproduction anyway. 🙏

@timneutkens
Copy link
Member

The underlying reason is probably this: https://github.com/captbaritone/jordaneldredge.com/blob/master/pages/%5Bslug%5D.js#L10-L12, keep in mind that the pages router has a list of dynamic routes in pages so next/link will end up matching that instead of the app route. This is intentional as app is set up to not ship a manifest of routes to the browser.

@captbaritone
Copy link
Author

Here's a branch which removes everything that's not needed (including trailingSlash: true.

https://github.com/captbaritone/jordaneldredge.com/tree/42513-repro

To repro:

[clone]
yarn
yarn build # NOTE: Not yarn dev
yarn start

Expected

The page defined in app/notes/page.js renders.

Actual

The page defined in pages/[slug].js renders, but if you hit refresh it reverts the expected behavior (above).

Also Note

If you use yarn dev we also get the expected behavior.

@timneutkens
Copy link
Member

Yeah it's just what I said in #42513 (comment). You'll want to change that link to a normal <a> instead.

@captbaritone
Copy link
Author

Thanks for clarifying. Is it a bug that this behavior is different in dev mode than in build mode?

@timneutkens
Copy link
Member

Potentially yeah, the production behavior is "correct", can't do much about this unfortunately, dev behavior always hits the dev server on navigation so might be that does navigate between pages<->app

@ijjk ijjk closed this as completed in d8d9b2c Nov 21, 2022
jankaifer pushed a commit to jankaifer/next.js that referenced this issue Nov 23, 2022
Currently in dev the `_devPagesManifest` includes the `/app` routes as
well. However, In production, the `_buildManifest.js` does not include
the `/app` routes. This causes the `/pages` router to behave differently
in the two environments.

This change excludes the `/app` routes from `_devPagesManifest` to make
it work the same in dev/prod.

Fixes vercel#42513
Fixes vercel#42532

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants