Skip to content

Commit 516d35e

Browse files
Merge pull request #21202 from johanrd/fix/14615
[BUGFIX] `current-when` with nested routes containing dynamic dynamic segments
2 parents 96427a6 + 565e36a commit 516d35e

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

packages/@ember/-internals/glimmer/lib/components/link-to.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,12 @@ class _LinkTo extends InternalComponent {
554554
if (typeof currentWhen === 'boolean') {
555555
return currentWhen;
556556
} else if (typeof currentWhen === 'string') {
557-
let { models, routing } = this;
557+
let { routing } = this;
558558

559559
return currentWhen
560560
.split(' ')
561561
.some((route) =>
562-
routing.isActiveForRoute(models, undefined, this.namespaceRoute(route), state)
562+
routing.isActiveForRoute([], undefined, this.namespaceRoute(route), state)
563563
);
564564
} else {
565565
let { route, models, query, routing } = this;

packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,37 @@ moduleFor(
925925
);
926926
}
927927

928+
async [`@test it supports custom, nested, current-when with route params`](assert) {
929+
assert.expect(2);
930+
this.router.map(function () {
931+
this.route('index', { path: '/' });
932+
this.route('foo', { path: '/foo/:fooId' }, function () {
933+
this.route('bar', { path: '/bar/:barId' });
934+
});
935+
});
936+
937+
this.addTemplate('index', `{{outlet}}`);
938+
this.addTemplate(
939+
'foo',
940+
`<LinkTo @route='foo.index' @model={{1}} @current-when='foo.index foo.bar'>Foo Index</LinkTo> {{outlet}}`
941+
);
942+
this.addTemplate(
943+
'foo.bar',
944+
`<LinkTo @route='foo.bar' @models={{array 1 2}}>Foo Bar</LinkTo>`
945+
);
946+
947+
await this.visit('/foo/1/bar/2');
948+
949+
assert.ok(
950+
this.$('a[href="/foo/1"]').is('.active'),
951+
'The link to foo.index should be active when on foo.bar'
952+
);
953+
assert.ok(
954+
this.$('a[href="/foo/1/bar/2"]').is('.active'),
955+
'The link to foo.bar should be active when on foo.bar'
956+
);
957+
}
958+
928959
async ['@test it does not disregard current-when when it is set via a bound param'](assert) {
929960
this.router.map(function () {
930961
this.route('index', { path: '/' }, function () {

packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,37 @@ moduleFor(
966966
);
967967
}
968968

969+
async [`@test it supports custom, nested, current-when with route params`](assert) {
970+
assert.expect(2);
971+
this.router.map(function () {
972+
this.route('index', { path: '/' });
973+
this.route('foo', { path: '/foo/:fooId' }, function () {
974+
this.route('bar', { path: '/bar/:barId' });
975+
});
976+
});
977+
978+
this.addTemplate('index', `{{outlet}}`);
979+
this.addTemplate(
980+
'foo',
981+
`{{#link-to route='foo.index' model=1 current-when='foo.index foo.bar'}}Foo Index{{/link-to}} {{outlet}}`
982+
);
983+
this.addTemplate(
984+
'foo.bar',
985+
`{{#link-to route='foo.bar' models=(array 1 2)}}Foo Bar{{/link-to}}`
986+
);
987+
988+
await this.visit('/foo/1/bar/2');
989+
990+
assert.ok(
991+
this.$('a[href="/foo/1"]').is('.active'),
992+
'The link to foo.index should be active when on foo.bar'
993+
);
994+
assert.ok(
995+
this.$('a[href="/foo/1/bar/2"]').is('.active'),
996+
'The link to foo.bar should be active when on foo.bar'
997+
);
998+
}
999+
9691000
async ['@test it does not disregard current-when when it is set via a bound param'](assert) {
9701001
this.router.map(function () {
9711002
this.route('index', { path: '/' }, function () {

0 commit comments

Comments
 (0)