HTTP 303 Redirects with anchor not respected
See original GitHub issueSteps to Reproduce:
- Redirect after a form submission (via HTTP 303) to a location that contains an anchor (e.g.
Location: /path#anchor
).
Observed Behavior:
- The redirection occurs, but strips the anchor from the resulting page (e.g.
/path
instead of/path#anchor
) - This results in any page rendering dependent upon this anchor to fail.
Expected Behavior
- Redirect and expose the full path with the anchor in the resulting page’s address bar.
Workaround
- Disable turbo on that particular form submission.
Wild Guess Hypothesis I suspect that the subsequent redirection fetch (from Turbo) strips the anchor tag from the underlying HTTP request (as expected), but when the page is re-hydrated, the address bar URL (pushstate) is not updated to reflect the original anchor.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:19
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Redirect with anchor and Turbo - Hotwire Discussion
I really need to redirect with an anchor. Based on the comments at HTTP 303 Redirects with anchor not respected · Issue #211...
Read more >303 See Other - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 303 See Other redirect status response code indicates that the redirects don't link to the requested ...
Read more >Why does my anchor link redirect to the same page?
This behaviour is due to your HTTP server which is either redirecting your back to / or serving up the same file for...
Read more >URL Redirects - Squarespace Help Center
Invalid mapping: Not enough parts. This means that a redirect is missing the arrow (->) or the redirect type (301 or 302).
Read more >How To Bulk Check Redirects - Screaming Frog
Check redirects for free by uploading a list of URLs in bulk or crawling a site. View the HTTP response code (301, 302)...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m seeing this behavior when performing any type of redirect after a successful form submission and the problem goes away if I disable Turbo. I’m also not using Rails so this is isolated to the JS library itself. I’m using beta 7 and I’m also not using frames or streams here. This is a basic full blown HTTP redirect.
Reproduceable steps:
import * as Turbo from "@hotwired/turbo";
Create a form where after the POST comes in, redirect to
/#foo
The
#foo
will get stripped out from the redirectComment out the line from step 1 and do the same thing and now the anchor is kept in tact.
It’s worth pointing out params are kept in tact in either case. I’m only losing the anchor with Turbo.
I can confirm that this is an issue and I find it quite an unexpected behavior and would love to use my anchors. Adding a tailing
/
does not solve the issue for me when doing redirects in the controller:In both cases the anchor is lost. Using 301, 302, 303 makes no difference. The only solution right now is to set
data-turbo=false
on the form.Any ideas how to fix this?