File tree Expand file tree Collapse file tree 3 files changed +18
-9
lines changed Expand file tree Collapse file tree 3 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -415,13 +415,13 @@ RouteRecognizer.prototype = {
415
415
if ( output . charAt ( 0 ) !== '/' ) { output = '/' + output ; }
416
416
417
417
if ( params && params . queryParams ) {
418
- output += this . generateQueryString ( params . queryParams , route . handlers ) ;
418
+ output += this . generateQueryString ( params . queryParams ) ;
419
419
}
420
420
421
421
return output ;
422
422
} ,
423
423
424
- generateQueryString : function ( params , handlers ) {
424
+ generateQueryString : function ( params ) {
425
425
var pairs = [ ] ;
426
426
var keys = [ ] ;
427
427
for ( var key in params ) {
Original file line number Diff line number Diff line change @@ -530,13 +530,22 @@ class Router {
530
530
_stringifyPath ( path ) {
531
531
if ( path && typeof path === 'object' ) {
532
532
if ( path . name ) {
533
- var params = path . params || { }
533
+ const params = path . params || { }
534
534
if ( path . query ) {
535
535
params . queryParams = path . query
536
536
}
537
537
return this . _recognizer . generate ( path . name , params )
538
538
} else if ( path . path ) {
539
- return path . path
539
+ let fullPath = path . path
540
+ if ( path . query ) {
541
+ const query = this . _recognizer . generateQueryString ( path . query )
542
+ if ( fullPath . indexOf ( '?' ) > - 1 ) {
543
+ fullPath += '&' + query . slice ( 1 )
544
+ } else {
545
+ fullPath += query
546
+ }
547
+ }
548
+ return fullPath
540
549
} else {
541
550
return ''
542
551
}
Original file line number Diff line number Diff line change @@ -244,18 +244,18 @@ describe('Core', function () {
244
244
component : {
245
245
template :
246
246
'<div>' +
247
- '<a id="link-a" v-link="{ path: \'b\' }">Link A</a>' +
247
+ '<a id="link-a" v-link="{ path: \'b\', query: { id: 123 } }">Link A</a>' +
248
248
'</div>'
249
249
}
250
250
} ,
251
251
'/b' : {
252
252
component : {
253
253
data : function ( ) {
254
- return { a : 'a' }
254
+ return { a : 'a?a=1 ' }
255
255
} ,
256
256
template :
257
257
'<div>' +
258
- '<a id="link-b" v-link="{ path: \'/\' + a }">Link B</a>' +
258
+ '<a id="link-b" v-link="{ path: \'/\' + a, query: { b: 2 } }">Link B</a>' +
259
259
'<a id="link-c" v-link="{ path: c }"></c>' +
260
260
'</div>'
261
261
}
@@ -283,12 +283,12 @@ describe('Core', function () {
283
283
nextTick ( function ( ) {
284
284
expect ( el . textContent ) . toBe ( 'Link A' )
285
285
var link = el . querySelector ( '#link-a' )
286
- expect ( link . getAttribute ( 'href' ) ) . toBe ( 'b' )
286
+ expect ( link . getAttribute ( 'href' ) ) . toBe ( 'b?id=123 ' )
287
287
click ( link )
288
288
nextTick ( function ( ) {
289
289
expect ( el . textContent ) . toBe ( 'Link B' )
290
290
var link = el . querySelector ( '#link-b' )
291
- expect ( link . getAttribute ( 'href' ) ) . toBe ( '/a' )
291
+ expect ( link . getAttribute ( 'href' ) ) . toBe ( '/a?a=1&b=2 ' )
292
292
// falsy expressions should not set href
293
293
expect ( el . querySelector ( '#link-c' ) . hasAttribute ( 'href' ) ) . toBe ( false )
294
294
click ( link )
You can’t perform that action at this time.
0 commit comments