diff --git a/lib/router.js b/lib/router.js index ba9c84d..2d67779 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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); }; diff --git a/test/client/router.core.spec.js b/test/client/router.core.spec.js index 160c911..c52f073 100644 --- a/test/client/router.core.spec.js +++ b/test/client/router.core.spec.js @@ -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;