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 treats initial dot incorrectly #33081

Closed
OZZlE opened this issue Jan 7, 2022 · 1 comment · Fixed by #36823
Closed

next/link treats initial dot incorrectly #33081

OZZlE opened this issue Jan 7, 2022 · 1 comment · Fixed by #36823
Labels
Navigation Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@OZZlE
Copy link

OZZlE commented Jan 7, 2022

Run next info (available from version 12.0.8 and up)

Operating System:
  Platform: Windows
  Arch: x64
  Version: Windows 10 Enterprise
Binaries:
  Node: 16.0.0
  npm: 7.10.0
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 12.0.7
  react: 17.0.2
  react-dom: 17.0.2

What version of Next.js are you using?

12.0.7

What version of Node.js are you using?

16.0.0

What browser are you using?

Chrome

What operating system are you using?

Windows 10

How are you deploying your application?

Only local project for now

Describe the Bug

At a page like https://www.example.com/suburl/

Using standard html syntax to link to a sub path <Link href="./path/"><a href="./path/">a</a></Link> next/link sends the user to the wrong url: example.com/path/ - it skips the dot which should be the current path.

Seems like it should be supported based on: #614

Expected Behavior

The link should lead to: https://www.example.com/suburl/path/ .

If you disable js in the browser you get the correct native bahavior of course.

To Reproduce

At a page like https://www.example.com/suburl/

next.config.mjs:

/**
 * @type {import('next').NextConfig}
 */
const nextConfig = {
    trailingSlash: true,
}
export default nextConfig

In a component:

<Link href="./path/">
  <a>link</a>
</Link>
@OZZlE OZZlE added the bug Issue was opened via the bug report template. label Jan 7, 2022
@balazsorban44 balazsorban44 added Navigation Related to Next.js linking (e.g., <Link>) and navigation. kind: bug and removed bug Issue was opened via the bug report template. labels Jan 7, 2022
kodiakhq bot pushed a commit that referenced this issue May 22, 2022
## Bug

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

Fixes #36823 
Closes #33084

The issue is caused by the `isLocalURL` function only checks if a URL starts with `/`, `#` or `?`. So a URL that starts with `.` will not be considered a "local URL". The PR fixes that by introducing a new util function `isAbsoluteUrl` that is fully compliant with [RFC3986](https://tools.ietf.org/html/rfc3986#section-4.3).
@ijjk ijjk closed this as completed May 22, 2022
@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 Jun 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Navigation Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
3 participants