Skip to content

fix(angular_1_router): ng-link is generating wrong hrefs#7423

Closed
davidreher wants to merge 4 commits into
angular:masterfrom
BROCKHAUS-AG:fix-angular-1-router-ng-link
Closed

fix(angular_1_router): ng-link is generating wrong hrefs#7423
davidreher wants to merge 4 commits into
angular:masterfrom
BROCKHAUS-AG:fix-angular-1-router-ng-link

Conversation

@davidreher
Copy link
Copy Markdown
Contributor

At the moment ng-link is generating html5mode URLs for hrefs. Instead it should check whether or not html5mode is enabled and create the hrefs accordingly.

The renaming in the getLink function is aligning it to RouterLink's _updateLink.

cc: @btford @petebacondarwin

At the moment ng-link is generating html5mode URLs for `href`s. Instead it should check whether or not html5mode is enabled and create the `href`s accordingly. The renaming in the `getLink` function is aligning it to `RouterLink`'s `_updateLink`.
@davidreher davidreher changed the title fix(angular_1_router): ng-link is generating wronf hrefs fix(angular_1_router): ng-link is generating wrong hrefs Mar 4, 2016
@petebacondarwin
Copy link
Copy Markdown
Contributor

I think you are right that this is a bug @davidreher. I think we can tighten up the implementation a bit.

Location.prototype.prepareExternalUrl = function(url) {
if (url.length > 0 && !url.startsWith('/')) {
url = '/' + url;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we always prepend a /?
Previously, HTML5 mode URLs were prepended with ./

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are right about the ./ I will fix that

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That being said it seems that the A2 Location may not do this so I am wondering which is wrong...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Did you already find out ;) ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'll talk to @btford about it on Monday

Conflicts:
	modules/angular1_router/src/ng_outlet.ts
	modules/angular1_router/test/ng_link_spec.js
@davidreher
Copy link
Copy Markdown
Contributor Author

@petebacondarwin the tests are now run with html5mode enabled and disabled. What about the base href? Any preferences how it should be set?

Btw. I am working on the failing tests, I need to setup a linux vm since windows build (and test) is not working atm (see #7457)

@davidreher
Copy link
Copy Markdown
Contributor Author

@petebacondarwin any ideas how to determine whether html5mode is enabled or not? In our application (angular 1.5) accessing $location.$$html5 works, but not in the angular component router tests :/

@petebacondarwin
Copy link
Copy Markdown
Contributor

I have been working on this today. The problem with the tests is that gulp buildRouter.dev actually does some regex replacing that accidentally changes $$html5 to $html5 :-(
I have made a number of changes to the tests and setup for this PR. I will push you a branch to look at shortly.

@petebacondarwin
Copy link
Copy Markdown
Contributor

Have a look at the last commit of #7489

@davidreher
Copy link
Copy Markdown
Contributor Author

Looks good, but how about running all tests in both configurations (0382d80 and 8869e82)?

@petebacondarwin
Copy link
Copy Markdown
Contributor

Yes. good idea. Now to think about baseHref...

@davidreher
Copy link
Copy Markdown
Contributor Author

@Mischi suggested to simply insert the base tag to the head and remove it afterwards ...

@petebacondarwin
Copy link
Copy Markdown
Contributor

I am not sure if that would mess with karma loading up files...
It might be safer to just mock out the $location service altogether and check that the Location class is calling the correct methods with the correct values.

@mgol
Copy link
Copy Markdown
Member

mgol commented Mar 18, 2016

I've just hit this bug. This is a blocker to migrating production apps using hashbang mode to the new router as all links would be broken if you right-clicked and pressed "Open in new tab".

@davidreher
Copy link
Copy Markdown
Contributor Author

@petebacondarwin how do we proceed? Shall I commit 0382d80 and 8869e82 to your pull request? What do we do about the base tag?

@petebacondarwin
Copy link
Copy Markdown
Contributor

OK, so I will merge your commits into my PR and add tests for base href changes...

petebacondarwin pushed a commit to petebacondarwin/angular that referenced this pull request Mar 21, 2016
At the moment ng-link is generating html5mode URLs for `href`s.
Instead it should check whether or not html5mode is enabled and create
the `href`s accordingly. The renaming in the `getLink` function is
aligning it to `RouterLink`'s `_updateLink`.

Closes angular#7423
@mhevery mhevery closed this in 69c1405 Mar 22, 2016
@davidreher davidreher deleted the fix-angular-1-router-ng-link branch March 22, 2016 18:01
@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants