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/navigation redirect error with relative URL #72765

Closed
Crane101 opened this issue Nov 13, 2024 · 3 comments · Fixed by #72770
Closed

next/navigation redirect error with relative URL #72765

Crane101 opened this issue Nov 13, 2024 · 3 comments · Fixed by #72770
Assignees
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@Crane101
Copy link

Link to the code that reproduces this issue

https://github.com/Crane101/next-15-relative-redirect-error

To Reproduce

  1. Start the application using npm run dev
  2. Open the root page
  3. Click Start to navigate to /lng/page1
  4. Click "Relative Redirect" to navigate to the relative url page2 via a server action

Current vs. Expected behavior

Expected Behaviour

The app navigates to /lng/page2

Actual Behaviour

An error is thrown: TypeError: Invalid URL

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
  Available memory (MB): 32466
  Available CPU cores: 24
Binaries:
  Node: 20.11.1
  npm: 10.2.4
  Yarn: 1.22.22
  pnpm: 9.6.0
Relevant Packages:
  next: 15.0.4-canary.8 // Latest available version is detected (15.0.4-canary.8).
  eslint-config-next: N/A
  react: 19.0.0-rc-5c56b873-20241107
  react-dom: 19.0.0-rc-5c56b873-20241107
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Navigation

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

The documentation for the redirect function states that the url parameter "Can be a relative or absolute path.", which was the case in next 14 - but after upgrading to v15 it seems that only absolute paths will work. From the error I'm guessing that it's using the verbatim relative path to create a new URL object?

Pretty essential for my use case as there does not appear to be a way to access the current url or route parameters from a server action in order to construct an absolute version of the url.

@Crane101 Crane101 added the bug Issue was opened via the bug report template. label Nov 13, 2024
@github-actions github-actions bot added the Navigation Related to Next.js linking (e.g., <Link>) and navigation. label Nov 13, 2024
@ztanner ztanner added the linear: next Confirmed issue that is tracked by the Next.js team. label Nov 13, 2024
@ztanner ztanner self-assigned this Nov 13, 2024
@ztanner
Copy link
Member

ztanner commented Nov 13, 2024

Hi @Crane101 - thanks for the report! The correct way to refer to a relative redirect here is via ./ or / or ../. There's currently a bug with ../ which will be fixed by #72770.

This used to work by accident in Next 14 but you may have noticed that it doesn't actually work correctly: it's doing a full page navigation to the destination URL rather a soft nav with streaming.

@Crane101
Copy link
Author

Yep looking good in canary (now that I have corrected my relative paths to use ../).
Awesome response time too, thanks @ztanner 👍

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. 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 Nov 28, 2024
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. linear: next Confirmed issue that is tracked by the Next.js team. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants