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

Make query string parameters work when using hashbang routing #551

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

5im-0n
Copy link
Contributor

@5im-0n 5im-0n commented Jan 4, 2020

When hashbang is true, urls like http://localhost/?foo=bar got
redirected to http://localhost/?foo=bar#!?foo=bar.
This duplicated the query string and made the url ugly.
This commit fixed this problem by making urls like
http://localhost/?foo=bar redirect to http://localhost/#!?foo=bar

I made some nightwatch tests to make sure all use cases are covered.
The tests can be found here: https://github.com/S2-/page.js-nightwatch-test

All urls work as expected:

hashbang: false

navigating to http://127.0.0.1:8001/ -> http://127.0.0.1:8001/
clicking a link href="/hello" -> http://127.0.0.1:8001/hello
clicking a link href="/hello?some=query&str=ing" -> http://127.0.0.1:8001/hello?some=query&str=ing
navigating to http://127.0.0.1:8001/?some=query&str=ing -> http://127.0.0.1:8001/?some=query&str=ing
navigating to http://127.0.0.1:8001/hello?some=query&str=ing -> http://127.0.0.1:8001/hello?some=query&str=ing


hashbang: true

navigating to http://127.0.0.1:8000/ -> http://127.0.0.1:8000/
clicking a link href="/hello" -> http://127.0.0.1:8000/#!/hello'
clicking a link href="/hello?some=query&str=ing" -> http://127.0.0.1:8000/#!/hello?some=query&str=ing'
navigating to http://127.0.0.1:8000/?some=query&str=ing -> http://127.0.0.1:8000/#!?some=query&str=ing'
navigating to http://127.0.0.1:8000/?some=query&str=ing#!/hello -> http://127.0.0.1:8000/#!/hello?some=query&str=ing'

When `hashbang` is `true`, urls like http://localhost/?foo=bar got
redirected to http://localhost/?foo=bar#!?foo=bar.
This duplicated the query string and made the url ugly.
This commit fixed this problem by making urls like
http://localhost/?foo=bar redirect to http://localhost/#!?foo=bar
@coveralls
Copy link

Coverage Status

Coverage increased (+0.06%) to 92.623% when pulling 3c1ca83 on S2-:qs-on-hash into 94138d1 on visionmedia:master.

@matthewp
Copy link
Collaborator

matthewp commented Jan 4, 2020

Thanks! Any chance you can add a test?

@5im-0n
Copy link
Contributor Author

5im-0n commented Jan 4, 2020

No sorry, I don't have mocha skills and no interest in learning yet an other testing framework. I hope the existing passing mocha tests are enough.

@matthewp
Copy link
Collaborator

matthewp commented Jan 5, 2020

Unfortunately there's been issues in the past where a fix with no test broke another case that also was untested. So we've made it a policy to only merge pull requests with tests, to prevent regressions.

@5im-0n
Copy link
Contributor Author

5im-0n commented Jan 5, 2020

Seems a good policy. I just don't have any mocha skills 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants