X Tutup
Skip to content

#5502 Bug: Don't prepend unnecessary '/' to path#6729

Closed
AlexBachmann wants to merge 1 commit intoangular:masterfrom
AlexBachmann:#5502-child-router
Closed

#5502 Bug: Don't prepend unnecessary '/' to path#6729
AlexBachmann wants to merge 1 commit intoangular:masterfrom
AlexBachmann:#5502-child-router

Conversation

@AlexBachmann
Copy link
Copy Markdown

This is a fix to the Child Router Issue as described in #5502.

I reproduced this bug in this Plunkr
http://plnkr.co/edit/OjXZK9

You will not get errors thrown displayed in the console while running in Plunkr so here is the exact same code on our servers
http://test.loop-one.de/

@googlebot
Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@AlexBachmann
Copy link
Copy Markdown
Author

I signed it.

@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

@petebacondarwin
Copy link
Copy Markdown
Contributor

@Batch1211 - thanks for this but it will need a unit test demonstrating the bug before it can be landed

@ericmartinezr
Copy link
Copy Markdown
Contributor

There's another PR for this #5724 not sure if the case mentioned in both issues are the same

@AlexBachmann
Copy link
Copy Markdown
Author

@petebacondarwin I would love to, but it is really hard to get the angular test suit (karma) working on my local machine. Is there documentation provided anywhere on how to set this all up?

@AlexBachmann
Copy link
Copy Markdown
Author

@petebacondarwin found it.

@petebacondarwin
Copy link
Copy Markdown
Contributor

@Batch1211 somewhere around here is probably where the test needs to go:

it('should change location path', inject(function ($location) {
$router.config([
{ path: '/user', component: 'userCmp' }
]);
compile('<div ng-outlet></div>');
$router.navigateByUrl('/user');
$rootScope.$digest();
expect($location.path()).toBe('/user');
}));
it('should change location to the canonical route', inject(function ($location) {
compile('<div ng-outlet></div>');
$router.config([
{ path: '/', redirectTo: ['/User'] },
{ path: '/user', component: 'userCmp', name: 'User' }
]);
$router.navigateByUrl('/');
$rootScope.$digest();
expect($location.path()).toBe('/user');
}));
it('should change location to the canonical route with nested components', inject(function ($location) {
registerComponent('childRouter', {
template: '<div>inner { <div ng-outlet></div> }</div>',
$routeConfig: [
{ path: '/new-child', component: 'oneCmp', name: 'NewChild'},
{ path: '/new-child-two', component: 'twoCmp', name: 'NewChildTwo'}
]
});
$router.config([
{ path: '/old-parent/old-child', redirectTo: ['/NewParent', 'NewChild'] },
{ path: '/old-parent/old-child-two', redirectTo: ['/NewParent', 'NewChildTwo'] },
{ path: '/new-parent/...', component: 'childRouter', name: 'NewParent' }
]);
compile('<div ng-outlet></div>');
$router.navigateByUrl('/old-parent/old-child');
$rootScope.$digest();
expect($location.path()).toBe('/new-parent/new-child');
expect(elt.text()).toBe('inner { one }');
$router.navigateByUrl('/old-parent/old-child-two');
$rootScope.$digest();
expect($location.path()).toBe('/new-parent/new-child-two');
expect(elt.text()).toBe('inner { two }');
}));
it('should navigate when the location path changes', inject(function ($location) {
$router.config([
{ path: '/one', component: 'oneCmp' }
]);
compile('<div ng-outlet></div>');
$location.path('/one');
$rootScope.$digest();
expect(elt.text()).toBe('one');
}));

You can run these tests from the root of the angular2 project by doing:

gulp test.unit.router

@AlexBachmann
Copy link
Copy Markdown
Author

@petebacondarwin Here is a failing unit test for you. This pull request will fix the issue.

One question for my understanding: I realize that the angular1_router uses the same codebase as the angular2 router. But why was I supposed to write the unit test for the angular1_router test suite?

@petebacondarwin
Copy link
Copy Markdown
Contributor

Oh good point. I might have pointed you to the wrong place :-)
On 30 Jan 2016 18:54, "Alexander Bachmann" notifications@github.com wrote:

@petebacondarwin https://github.com/petebacondarwin Here is a failing
unit test for you. This pull request will fix the issue.

One question for my understanding: I realize that the angular1_router uses
the same codebase as the angular2 router. But why was I supposed to write
the unit test for the angular1_router test suite?


Reply to this email directly or view it on GitHub
#6729 (comment).

@AlexBachmann
Copy link
Copy Markdown
Author

@petebacondarwin I added the second unit test

@btford
Copy link
Copy Markdown
Contributor

btford commented Feb 1, 2016

LGTM, @Batch1211 can you squash these into a single commit?

@AlexBachmann
Copy link
Copy Markdown
Author

@btford Yes I can. But just for my understanding: Why is that helpful?

@btford
Copy link
Copy Markdown
Contributor

btford commented Feb 1, 2016

It's easier to understand the history (git log) with this fix and tests as a single, atomic change.

In short, it helps communicate the intent of the change better, and makes it easier for others to see what the "finished" change is.

@petebacondarwin
Copy link
Copy Markdown
Contributor

@btford can we not leave the PR as is and squash it when we merge?

@alexeagle
Copy link
Copy Markdown
Contributor

Please clean up the history by squashing the commits:
http://blog.steveklabnik.com/posts/2012-11-08-how-to-squash-commits-in-a-github-pull-request

@vsavkin vsavkin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Feb 1, 2016
@googlebot
Copy link
Copy Markdown

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.

@googlebot googlebot added cla: no and removed cla: yes labels Feb 2, 2016
@AlexBachmann
Copy link
Copy Markdown
Author

Oh no. I made it worse. I'm sorry. I'm not a git-expert when it comes to squashing and rebasing. I'll create a new pull request, where everything is in one commit.

Added unit test for angular2 router test suite

This is the the second unit test for the #6729 pull request, which in turn is a fix for the #5502 issue

This change fixes the pushState Problem

Added unit test for angular2 router test suite

This is the the second unit test for the #6729 pull request, which in turn is a fix for the #5502 issue

Squashing some commits
@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Feb 2, 2016
@AlexBachmann
Copy link
Copy Markdown
Author

@btford Please tell me, that this is correct now :)

var emitPath = instruction.toUrlPath();
var emitQuery = instruction.toUrlQuery();
if (emitPath.length > 0) {
if (emitPath.length > 0 && emitPath[0] !== '/') {
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 wonder if we are allowed to do this without using some StringWrapper method?

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 checked with ts2dart and the online dartlang testbed and this is fine.

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.

Apparently we need to use != to compare the strings as in Dart equivalent strings are not always identical

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.

Could we file an issue in ts2dart to detect the unsupported code pattern so we don't fall victim to it again?

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.

Will do!

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.

@petebacondarwin petebacondarwin changed the title #5502 Bug: Child Routers on Root Components with path '/' must throw pushstate error #5502 Bug: Don't prepend unnecessary '/' to path Feb 7, 2016
@petebacondarwin petebacondarwin added pr_state: LGTM action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 7, 2016
petebacondarwin pushed a commit to petebacondarwin/angular that referenced this pull request Feb 8, 2016
@IgorMinar IgorMinar closed this in c603643 Feb 9, 2016
@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.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes type: bug/fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

X Tutup