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
This fixes #684.
  • Loading branch information
AlexanderS committed Sep 28, 2016
1 parent fb268d5 commit 3fa8c28
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Router.prototype.url = function() {
// automatically by `Meteor.absoluteUrl` as documented in:
// http://docs.meteor.com/#/full/meteor_absoluteurl
var completePath = this.path.apply(this, arguments);
var basePath = this._basePath || '/';
var basePath = '/' + (this._basePath || '') + '/';
basePath = basePath.replace(/\/\/+/g, "/");
var pathWithoutBase = completePath.replace(new RegExp('^' + basePath), '');
return Meteor.absoluteUrl(pathWithoutBase);
};
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 3fa8c28

Please sign in to comment.