Skip to content

Commit

Permalink
Try to fix #17963 (#17971)
Browse files Browse the repository at this point in the history
Try to fix #17963

Co-authored-by: Dan Gebhardt <[email protected]>
  • Loading branch information
rwjblue and dgeb authored Jun 14, 2019
2 parents 7734bac + efbc937 commit 37a1942
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/@ember/-internals/glimmer/lib/components/link-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,9 @@ if (EMBER_GLIMMER_ANGLE_BRACKET_BUILT_INS) {
_currentRouterState: alias('_routing.currentState'),
_targetRouterState: alias('_routing.targetState'),

_route: computed('route', '_currentRoute', function computeLinkToComponentRoute(this: any) {
_route: computed('route', '_currentRouterState', function computeLinkToComponentRoute(
this: any
) {
let { route } = this;
return route === UNDEFINED ? this._currentRoute : route;
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,77 @@ if (EMBER_GLIMMER_ANGLE_BRACKET_BUILT_INS) {
});
}

['@test generates proper href for `LinkTo` with no @route after transitioning to an error route GH#17963'](
assert
) {
this.router.map(function() {
this.route('bad');
});

this.add(
'controller:application',
Controller.extend({
queryParams: ['baz'],
})
);

this.add(
'route:bad',
Route.extend({
model() {
throw new Error('bad!');
},
})
);

this.addTemplate('error', `Error: {{model.message}}`);

this.addTemplate(
'application',
`
<LinkTo id="bad-link" @route="bad">
Bad
</LinkTo>
<LinkTo id="good-link" @query={{hash baz='lol'}}>
Good
</LinkTo>
{{outlet}}
`
);

return this.visit('/')
.then(async () => {
assert.equal(this.$('#good-link').length, 1, 'good-link should be in the DOM');
assert.equal(this.$('#bad-link').length, 1, 'bad-link should be in the DOM');

let goodLink = this.$('#good-link');
assert.equal(goodLink.attr('href'), '/?baz=lol');

return this.visit('/bad');
})
.then(() => {
assert.equal(this.$('#good-link').length, 1, 'good-link should be in the DOM');
assert.equal(this.$('#bad-link').length, 1, 'bad-link should be in the DOM');

let goodLink = this.$('#good-link');
// should still be / because we never entered /bad (it errored before being fully entered)
// and error states do not get represented in the URL, so we are _effectively_ still
// on /
assert.equal(goodLink.attr('href'), '/?baz=lol');

runTask(() => this.click('#good-link'));

let applicationController = this.getController('application');
assert.deepEqual(
applicationController.getProperties('baz'),
{ baz: 'lol' },
'index controller QP properties updated'
);
});
}

['@test supplied QP properties can be bound'](assert) {
this.addTemplate(
'index',
Expand Down

0 comments on commit 37a1942

Please sign in to comment.