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

[FEATURE query-params] Allow link-to helper to work without route #3410

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/ember-routing/lib/helpers/link_to.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,16 @@ Ember.onLoad('Ember.Handlebars', function(Handlebars) {
types = options.types,
data = options.data;

if (Ember.FEATURES.isEnabled("query-params")) {
if (parameters.params.length === 0) {
var appController = this.container.lookup('controller:application');
return [get(appController, 'currentRouteName')];
} else {
return resolveParams(parameters.context, parameters.params, { types: types, data: data });
}
}

// Original implementation if query params not enabled
return resolveParams(parameters.context, parameters.params, { types: types, data: data });
}).property(),

Expand Down
29 changes: 29 additions & 0 deletions packages/ember/tests/helpers/link_to_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,35 @@ if (Ember.FEATURES.isEnabled("query-params")) {
promise.then(next, shouldNotHappen);
});
});



test("The {{linkTo}} can work without a route name if query params are supplied", function() {
expect(4);

Router.map(function() {
this.route("items", { queryParams: ['page'] });
this.route('about');
});

Ember.TEMPLATES.items = Ember.Handlebars.compile("<h1>Items</h1> {{#linkTo page=2 id='next-page'}}Next Page{{/linkTo}}");

bootApplication();

Ember.run(function() {
router.handleURL("/items");
});

equal(normalizeUrl(Ember.$('#next-page').attr('href')), '/items?page=2', "The link-to works without a routename");
shouldNotBeActive('#next-page');

Ember.run(function() {
Ember.$('#next-page', '#qunit-fixture').click();
});

equal(router.get('url'), "/items?page=2", "Clicking the link updates the url");
shouldBeActive('#next-page');
});
}

test("The {{link-to}} helper's bound parameter functionality works as expected in conjunction with an ObjectProxy/Controller", function() {
Expand Down