-
Notifications
You must be signed in to change notification settings - Fork 326
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
fix: make redirection work when page is not existing in previous version #1350
Conversation
don't ask me why but adding an extra |
I thought I noticed that behavior last week on the other PR but somehow didn't believe / didn't figure out that it really was the |
does not work on PR build, but that's still because of CORS:
|
@drammock you've been too fast, I updated the main comment and I think I found the main reason. I don't see CORS error on my system with the latest build (Firefox on a Win 11) is it still an issue for you ? |
yes I still see the issue. If I go here: https://pydata-sphinx-theme--1350.org.readthedocs.build/en/1350/user_guide/install.html and use version switcher to go to latest or stable, I still end up at the homepage of latest or stable, not the installation page. And here's the relevant bit of the browser log: |
ok, that's actually expected as it's going from the "pydata-sphinx-theme--1350.org.readthedocs.build" domain to "pydata-sphinx-theme.readthedocs.io" so fetch is raising an error 200 and redirecting, which is what we want rignt ? |
Yes I know it's expected (at least it's not what you were hoping to fix here). But it's not what we want; we only want to redirect when the page doesn't exist so in an ideal world we would be able to set the CORS origin policy on the side note: it's not One thought: the server returns status code |
when I run |
Ok now I get why I manage to make it work, I customized my chrome instance to remove CORS (100% unsafe) for testing purposes. |
ha. that explains it. Well, let's take the plunge and see if it works on |
Fix #1343
EDIT:
Ok I got it, in short
return false
is one way to prevent many things but is not robust on every browser. Per se a listener should not return anything. It's an old jquery way of doing things that as been implemented by many browsers. It does the following:To make it more robust I replaced the return statement by the only thing we need:
event.preventDefault
Note that it will not work if you use a right-click as you select "open link in a new tab" which will not trigger any redirection.
resources:
https://stackoverflow.com/questions/10219073/html-how-to-prevent-the-browser-from-opening-the-link-specified-in-href
https://web.archive.org/web/20140724160732/http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/