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

fix(route-href): prefix the pathname for fragment hrefs #83

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

Conversation

pat841
Copy link
Contributor

@pat841 pat841 commented Sep 20, 2018

It seems when a <base> tag is used and a url contains something like index.html?some=query then the route-href sets an incorrect href link.

To reproduce:

  1. Go to http://next.plnkr.co/edit/UylHNVG2IKkUlBHK
  2. Run the preview and navigate to the http://run.plnkr.co/preview/<ID>/index.html?testing=true url that is printed in a new tab.
  3. Attempt to click on NEXT PAGE and see the page force refresh back to #/next-page then back to index.html?testing=true#/home

This fix adds the windows pathname and search query before the href fragment so that it does not force a new page load.

@pat841 pat841 force-pushed the feature/route-href-fix branch 3 times, most recently from bee7fde to b0d1179 Compare September 20, 2018 23:49
@pat841
Copy link
Contributor Author

pat841 commented Oct 10, 2018

Would you mind taking a look @EisenbergEffect

@EisenbergEffect
Copy link
Contributor

@davismj is our router lead. Matt, any thoughts on this?

@@ -47,6 +47,11 @@ export class RouteHref {

let href = this.router.generate(this.route, this.params);

// Ensure fragments are created correctly
if (href.startsWith('#') && window.location) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this approach will not make it in. Though in your case it does probably fix the issue, there are two key problems. First, and most importantly, we don't and can't depend on the window object as this can be run in node in a SSR scenario. Second, this code should be relegated to the this.router.generate function.

Copy link
Member

@davismj davismj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely related to aurelia/router#451 or aurelia/router#252.

A PR that resolves this issue must:

  • not depend on window, use the router.baseUrl instead
  • have a consistent behavior with or without pushState
  • have a consistent behavior with or without query parameters
  • contain tests that verify the behavior works in both of the above scenarios for various urls

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