Skip to content

Commit

Permalink
add url function which returns the absolute url for a path
Browse files Browse the repository at this point in the history
fixes #373
  • Loading branch information
Joakim Reinert committed Oct 30, 2015
1 parent 82f9573 commit ab1c1c6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Router.prototype.url = function() {
var path = this.path.apply(this, arguments);
return Meteor.absoluteUrl(path.replace(/^\//, ''));
};
3 changes: 3 additions & 0 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Package.onTest(function(api) {
api.addFiles('test/server/plugins/fast_render.js', 'server');

api.addFiles('test/common/router.path.spec.js', ['client', 'server']);
api.addFiles('test/common/router.url.spec.js', ['client', 'server']);
api.addFiles('test/common/router.addons.spec.js', ['client', 'server']);
api.addFiles('test/common/route.spec.js', ['client', 'server']);
});
Expand Down Expand Up @@ -75,4 +76,6 @@ function configure(api) {
api.addFiles('server/_init.js', 'server');

api.addFiles('server/plugins/fast_render.js', 'server');

api.addFiles('lib/router.js', ['client', 'server']);
}
11 changes: 11 additions & 0 deletions test/common/router.url.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Tinytest.add('Common - Router - url - generic', function (test) {
var pathDef = "/blog/:blogId/some/:name";
var fields = {
blogId: "1001",
name: "superb"
};
var expectedUrl = "http://localhost:3000/blog/1001/some/superb";

var path = FlowRouter.url(pathDef, fields);
test.equal(path, expectedUrl);
});

0 comments on commit ab1c1c6

Please sign in to comment.