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: Router ignored the root when creating hrefs #601

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rluba
Copy link
Contributor

@rluba rluba commented Jun 1, 2018

Aurelia router generated absolute paths but did not append the root path (ie. <base href="…">). This is incorrect and caused all non-default click actions (eg. CMD+Click, Right-click-> "Open in new Tab/Browser", etc.) to navigate to the wrong URL (see issue #457) and also broke links for crawlers.

Normal clicks only worked because they are intercepted by Aurelia and forwarded to aurelia-browser-history, which contains a corresponding bug that treats all URLs as fragments instead of expecting the base path to be present in absolute paths.

This fix requires the corresponding fix for aurelia-browser-history or the history will forward incorrect fragments to the router.

This caused all non-default click actions (eg. CMD+Click, Right-click-> "Open in new Tab/Browser", etc.) to navigate to the wrong URL
@CLAassistant
Copy link

CLAassistant commented Jun 1, 2018

CLA assistant check
All committers have signed the CLA.

@rluba
Copy link
Contributor Author

rluba commented Jun 5, 2018

Don’t merge this PR yet.
I’ve discovered that this solution doesn’t work in all cases and that there are more issues when root is set to something else than /. I’ll test it more thoroughly and keep you updated.

@rluba
Copy link
Contributor Author

rluba commented Jun 5, 2018

I discovered that redirects via route configurations, eg., {route: '', name: 'home', redirect: 'somepath'}, are broken when using my PR. But while trying to fix this, I discovered that these redirects are generally broken on master (as of 5fcb6f4).

There are multiple issues:

  1. Since 487c33d: TypeError: Cannot read property 'childRouter' of undefined is thrown because determineWhatToLoad(…) tries to interpret the Redirect plan as a regular plan .
  2. Since aafa070: _buildNavigationPlan(…) calls _createNavigationInstruction(…) and then generate(…) on a router before it knows it’s baseURL, causing it to pass incorrect URLs to new Redirect(…). This probably cancels out when there’s no root set, but it prevents me from fixing the redirect when a root is set.

Are these issues already known?

…because they’re generated when the router does not yet know its `baseUrl`. We therefore need to infer it from the navigation instruction.
@rluba
Copy link
Contributor Author

rluba commented Jun 5, 2018

  1. is fixed in a separate PR (Fix error introduced in 487c33d5 (when trying to fix #480) #603)
  2. is fixed in 0737128

The test coverage for this module is pretty horrible. I’ll help bring it up in the future if we decide to stick with Aurelia.

@davismj davismj self-assigned this Aug 1, 2018
@davismj
Copy link
Member

davismj commented Aug 1, 2018

The test coverage for this module is pretty horrible. I’ll help bring it up in the future if we decide to stick with Aurelia.

That is a generous assessment lol. Part of the reason Router dev has been slow recently is I find myself spending more time fixing the tests than getting to actual issues, and its very time consuming.

Thanks for your hard work. These are on my radar.

@mreiche
Copy link

mreiche commented Apr 15, 2019

Can someone please update this PR and merge it finally? This requirement is still unsatisfied.

@bigopon
Copy link
Member

bigopon commented Apr 15, 2019

@mreiche We are waiting for this PR at #632 to get merged, and then I'll incorporate @rluba changes in a new PR, or would be even better if @rluba could create PR based on refactored code.

@mreiche
Copy link

mreiche commented Oct 16, 2020

#632 has been merged a while ago.

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.

5 participants