@@ -48,7 +48,7 @@ var Router = function () {
4848 function Router ( context , routes ) {
4949 _classCallCheck ( this , Router ) ;
5050
51- this . context_ = context || { base_url : '' , prefix : '' , host : '' , scheme : '' } ;
51+ this . context_ = context || { base_url : '' , prefix : '' , host : '' , port : '' , scheme : '' } ;
5252 this . setRoutes ( routes || { } ) ;
5353 }
5454
@@ -73,6 +73,9 @@ var Router = function () {
7373 if ( 'prefix' in data ) {
7474 this . setPrefix ( data [ 'prefix' ] ) ;
7575 }
76+ if ( 'port' in data ) {
77+ this . setPort ( data [ 'port' ] ) ;
78+ }
7679
7780 this . setHost ( data [ 'host' ] ) ;
7881 this . setScheme ( data [ 'scheme' ] ) ;
@@ -168,6 +171,29 @@ var Router = function () {
168171 return this . context_ . host ;
169172 }
170173
174+ /**
175+ * @param {string } port
176+ */
177+
178+ } , {
179+ key : 'setPort' ,
180+ value : function setPort ( port ) {
181+ this . context_ . port = port ;
182+ }
183+
184+ /**
185+ * @return {string }
186+ */
187+
188+ } , {
189+ key : 'getPort' ,
190+ value : function getPort ( ) {
191+ return this . context_ . port ;
192+ }
193+ } , {
194+ key : 'buildQueryParams' ,
195+
196+
171197 /**
172198 * Builds query string params added to a URL.
173199 * Port of jQuery's $.param() function, so credit is due there.
@@ -176,9 +202,6 @@ var Router = function () {
176202 * @param {Array|Object|string } params
177203 * @param {Function } add
178204 */
179-
180- } , {
181- key : 'buildQueryParams' ,
182205 value : function buildQueryParams ( prefix , params , add ) {
183206 var _this = this ;
184207
@@ -245,7 +268,8 @@ var Router = function () {
245268 unusedParams = _extends ( { } , params ) ,
246269 url = '' ,
247270 optional = true ,
248- host = '' ;
271+ host = '' ,
272+ port = typeof this . getPort ( ) == "undefined" || this . getPort ( ) === null ? '' : this . getPort ( ) ;
249273
250274 route . tokens . forEach ( function ( token ) {
251275 if ( 'text' === token [ 0 ] ) {
@@ -324,8 +348,8 @@ var Router = function () {
324348 url = route . requirements [ "_scheme" ] + "://" + ( host || this . getHost ( ) ) + url ;
325349 } else if ( "undefined" !== typeof route . schemes && "undefined" !== typeof route . schemes [ 0 ] && this . getScheme ( ) !== route . schemes [ 0 ] ) {
326350 url = route . schemes [ 0 ] + "://" + ( host || this . getHost ( ) ) + url ;
327- } else if ( host && this . getHost ( ) !== host ) {
328- url = this . getScheme ( ) + "://" + host + url ;
351+ } else if ( host && this . getHost ( ) !== host + ( '' === port ? '' : ':' + port ) ) {
352+ url = this . getScheme ( ) + "://" + host + ( '' === port ? '' : ':' + port ) + url ;
329353 } else if ( absolute === true ) {
330354 url = this . getScheme ( ) + "://" + this . getHost ( ) + url ;
331355 }
0 commit comments