Skip to content

Commit

Permalink
Fix generation of URLs with a ROOT_URL containing a path
Browse files Browse the repository at this point in the history
 - Fix generation of URLs with a ROOT_URL containing a path, see [PR
kadirahq#691](kadirahq#691)
  • Loading branch information
dr-dimitru committed Feb 23, 2017
1 parent 4c9e746 commit 9a03cb5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Router.prototype.url = function() {
// We need to remove the leading base path, or "/", as it will be inserted
// automatically by `Meteor.absoluteUrl` as documented in:
// http://docs.meteor.com/#/full/meteor_absoluteurl
return Meteor.absoluteUrl(pathWithoutBase = this.path.apply(this, arguments).replace(new RegExp('^' + (this._basePath || '/')), ''));
return Meteor.absoluteUrl(this.path.apply(this, arguments).replace(new RegExp('^' + ('/' + (this._basePath || '') + '/').replace(/\/\/+/g, "/")), ''));
};

Meteor.startup(() => {
Expand Down
13 changes: 13 additions & 0 deletions test/client/router.core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,19 @@ function(test, done) {
resetBasePath();
});

Tinytest.add(
'Client - Router - base path - url generation',
function(test, done) {
_.each(['/flow', '/flow/', 'flow/', 'flow'], function(simulatedBasePath) {
var rand = Random.id();
setBasePath(simulatedBasePath);

Meteor.absoluteUrl.defaultOptions.rootUrl = 'http://example.com/flow'
test.equal(FlowRouter.url('/' + rand), 'http://example.com/flow/' + rand);
});
resetBasePath();
});


function setBasePath(path) {
FlowRouter._initialized = false;
Expand Down

0 comments on commit 9a03cb5

Please sign in to comment.