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 ember-eager-url-update] link-to should generate the url if it eagerly updates it, not use the href because it includes rootURL. Fixes #1244 #4312

Merged
merged 1 commit into from
Feb 6, 2014
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/ember-routing/lib/helpers/link_to.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,12 @@ Ember.onLoad('Ember.Handlebars', function(Handlebars) {
// Schedule eager URL update, but after we've given the transition
// a chance to synchronously redirect.
if (Ember.FEATURES.isEnabled("ember-eager-url-update")) {
var href = get(this, 'href');
if (typeof href === 'undefined') {
href = router.generate.apply(router, get(this, 'routeArgs'));
}
Ember.run.scheduleOnce('routerTransitions', this, this._eagerUpdateUrl, transition, href);
// We need to always generate the URL instead of using the href because
// the href will include any rootURL set, but the router expects a URL
// without it! Note that we don't use the first level router because it
// calls location.formatURL(), which also would add the rootURL!
var url = router.router.generate.apply(router.router, get(this, 'routeArgs'));
Ember.run.scheduleOnce('routerTransitions', this, this._eagerUpdateUrl, transition, url);
}
},

Expand Down
39 changes: 38 additions & 1 deletion packages/ember/tests/helpers/link_to_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ test("Issue 4201 - Shorthand for route.index shouldn't throw errors about contex
});

test("The {{link-to}} helper unwraps controllers", function() {
expect(2);
expect(3);

Router.map(function() {
this.route('filter', { path: '/filters/:filter' });
Expand Down Expand Up @@ -1410,6 +1410,43 @@ if (Ember.FEATURES.isEnabled("ember-eager-url-update")) {
basicEagerURLUpdateTest(false);
});

test("when link-to eagerly updates url, the path it provides does NOT include the rootURL", function() {
expect(2);

// HistoryLocation is the only Location class that will cause rootURL to be
// prepended to link-to href's right now
var HistoryTestLocation = Ember.HistoryLocation.extend({
// Don't actually touch the URL
replaceState: function(path) {},
pushState: function(path) {},

setURL: function(path) {
set(this, 'path', path);
},

replaceURL: function(path) {
set(this, 'path', path);
}
});

container.register('location:historyTest', HistoryTestLocation);

Router.reopen({
location: 'historyTest',
rootURL: '/app/'
});

bootApplication();

// href should have rootURL prepended
equal(Ember.$('#about-link').attr('href'), '/app/about');

Ember.run(Ember.$('#about-link'), 'click');

// Actual path provided to Location class should NOT have rootURL
equal(router.get('location.path'), '/about');
});

test("non `a` tags also eagerly update URL", function() {
basicEagerURLUpdateTest(true);
});
Expand Down