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

<Link href="/link" /> forwards to "/link.txt" #48996

Closed
1 task done
hariria opened this issue Apr 30, 2023 · 20 comments
Closed
1 task done

<Link href="/link" /> forwards to "/link.txt" #48996

hariria opened this issue Apr 30, 2023 · 20 comments
Labels
bug Issue was opened via the bug report template. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@hariria
Copy link

hariria commented Apr 30, 2023

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.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000
    Binaries:
      Node: 16.14.2
      npm: 9.2.0
      Yarn: 1.22.19
      pnpm: 7.25.1
    Relevant packages:
      next: 13.3.0
      eslint-config-next: N/A
      react: N/A
      react-dom: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

Routing (next/router, next/navigation, next/link)

Link to the code that reproduces this issue

N/A

To Reproduce

next.config.js

/** @type {import('next').NextConfig} */

const withNextra = require('nextra')({
  theme: 'nextra-theme-docs',
  themeConfig: './theme.config.jsx',
})

let withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true',
})

const nextConfig = {
  reactStrictMode: true,
  experimental: {
    appDir: true,
  },
  images: {
    unoptimized: true,
  },
  output: 'export',
}

if (process.env.NODE_ENV === 'production') {
  module.exports = withNextra(nextConfig)
} else if (process.env.NODE_ENV === 'development') {
  module.exports = withBundleAnalyzer(withNextra(nextConfig))
}
  1. Create a Nextra project with Next.js (currently using [email protected])
  2. Run yarn build to compile as a static site (via output: 'export' in next.config.js)
  3. Serve site via npx serve@latest out

Describe the Bug

import Link from 'next/link';

The <Link href="/docs" /> components I'm using redirect to "/docs.txt", not "/docs" for some reason. It only happens on static export as well (it's fine when I modify my next.config.js to be a non-static export).

Similar to this: #48414 except I'm using [email protected] and they're using github pages.

Expected Behavior

Expect it to go to "/docs"

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

npx serve@latest out

@hariria hariria added the bug Issue was opened via the bug report template. label Apr 30, 2023
@github-actions github-actions bot added the Navigation Related to Next.js linking (e.g., <Link>) and navigation. label Apr 30, 2023
@MangoQuiz
Copy link

MangoQuiz commented May 3, 2023

I'm having trouble with this stuff too.

Discussion:
#49098

Question in StackOverFlow:
https://stackoverflow.com/questions/76157727/next-js-13-3-appends-txt-to-urls-when-navigating-pages

I also did output: "export" like you do.

I'm waiting the soluition ;(

@dhruvilxcode
Copy link

it doesn't work either for export: standalone

If anyone can suggest or provide fix would be good!

@dhruvilxcode
Copy link

ok i found the fix,
i downgraded next version to 13.2

npm i [email protected]

and it worked well for me.

@MangoQuiz
Copy link

ok i found the fix, i downgraded next version to 13.2

npm i [email protected]

and it worked well for me.

Oh GOD!
I fixed it too.
I downgraded it version to "13.2.0"

Thanks.

@timneutkens
Copy link
Member

@hariria Nexta doesn't support App Router / output: 'export' yet.

@MangoQuiz the reason it breaks for you is because you're using output: 'export' incorrectly. You can't use next start when using output: 'export'. You have to use a static file server instead.
If you're using next start it's better to not add output: 'export' to next.config.js. Static pages are already the default.

@dhruvilxcode output: 'standalone' is a different feature, we're working on a fix here: #49116

@MangoQuiz
Copy link

MangoQuiz commented May 3, 2023

@timneutkens Thank you for replying! I'm kinda newbie in web development.

If you don't mind me asking, how can I use a static file server in details? Remove output: 'export' after build it? or next build and next start without output: 'export'

@dhruvilxcode
Copy link

@timneutkens even without standalone export feature, it's not working for that too.

Note: I am using middleware with appDir enabled.

@timneutkens
Copy link
Member

Please open a new issue with a complete reproduction 🙏

@dhruvilxcode
Copy link

#49130

@thangcmo
Copy link

thangcmo commented May 5, 2023

ok i found the fix, i downgraded next version to 13.2

npm i [email protected]

and it worked well for me.

I fixed it too.
I downgraded it version to "13.2.3"

@leonahliang90
Copy link

leonahliang90 commented May 21, 2023

even have downgraded to version 13.2.3, it might work for this Link href, but anything below 13.3 version would not have export feature ready if your appDir is true.

experimental: {
    appDir: true,
  },

either wait for official fix or change from App Router to Page Router

@y0zong
Copy link

y0zong commented Jun 2, 2023

@timneutkens

@hariria Nexta doesn't support App Router / output: 'export' yet.

I have same problem here when I try to deploy SPA project(output: 'export' ) to Nginx, does Nextjs team have any plan to support it?

@Afellman
Copy link

I have this issue using router.push with output: "export". When I try to navigate to home with router.push("/") it tries to fetch a .txt file...

@batazor
Copy link

batazor commented Jun 27, 2023

I confirm, this is a very strange behavior, I see that in the code for some reason make the concatenation of the path with .txt maybe we can remove it?

@deyvisonborges
Copy link

This script solves your problem.
Replace the start command with:

package.json

{
  "start": "npx serve ./build/"
}

@batazor
Copy link

batazor commented Jun 28, 2023

@deyvisonborges I use export and my docker image has only nginx, I can't run npx, node, etc

@dscafati
Copy link

This is fixed at least on 13.4.7, could you all please check that?

@htakemoto
Copy link

I confirmed that the version 13.4.7 fixed the link issue with output: 'export' in next.config.js, however, if the url path is longer than 56 chars, the link is cut in the middle.

@timneutkens
Copy link
Member

This issue was indeed fixed in this PR: https://github.com/vercel/next.js/pull/50974/files#diff-7b6239af735eba0c401e1a0db1a04dd4575c19a031934f02d128cf3ac813757bR73-R81

@htakemoto happy to take a look at what you're running into, but can't reproduce it. Can you open a new issue that explains how to reproduce it? Thanks!

hywlss9 added a commit to hywlss9/hywlss9.github.io that referenced this issue Jul 9, 2023
- next/link로 page 이동시 뒤에 .link 확장자가 붙는 에러 때문에 downgrade 함
vercel/next.js#48996
@github-actions
Copy link
Contributor

github-actions bot commented Aug 3, 2023

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 added the locked label Aug 3, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2023
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. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
Development

No branches or pull requests