File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -150,8 +150,8 @@ export interface IRoute<
150150
151151 createUrl (
152152 ...args : IsPartial < TInputParams > extends true
153- ? [ params ?: Maybe < TInputParams > , query ?: AnyObject ]
154- : [ params : TInputParams , query ?: AnyObject ]
153+ ? [ params ?: Maybe < TInputParams > , query ?: AnyObject , mergeQuery ?: boolean ]
154+ : [ params : TInputParams , query ?: AnyObject , mergeQuery ?: boolean ]
155155 ) : string ;
156156
157157 destroy ( ) : void ;
Original file line number Diff line number Diff line change 1+ import { buildSearchString } from 'mobx-location-history' ;
2+ import { routeConfig } from '../config/config.js' ;
3+ import type { RouteNavigateParams } from '../route/route.types.js' ;
4+
5+ export const buildUrl = ( path : string , navigateParams : RouteNavigateParams ) => {
6+ const query =
7+ ( navigateParams . mergeQuery ?? routeConfig . get ( ) . mergeQuery )
8+ ? {
9+ ...routeConfig . get ( ) . queryParams . data ,
10+ ...navigateParams . query ,
11+ }
12+ : ( navigateParams . query ?? { } ) ;
13+
14+ return `${ path } ${ buildSearchString ( query ) } ` ;
15+ } ;
Original file line number Diff line number Diff line change 1- import { buildSearchString } from 'mobx-location-history' ;
21import { observer } from 'mobx-react-lite' ;
32import {
43 type AnchorHTMLAttributes ,
@@ -15,6 +14,7 @@ import {
1514 type RouteNavigateParams ,
1615 routeConfig ,
1716} from '../../core/index.js' ;
17+ import { buildUrl } from '../../core/utils/build-url.js' ;
1818
1919interface LinkAnchorProps
2020 extends Omit < AnchorHTMLAttributes < HTMLAnchorElement > , 'href' > {
@@ -79,15 +79,14 @@ export const Link = observer(
7979 if ( outerHref ) {
8080 href = outerHref ;
8181 } else {
82- const query =
83- ( mergeQuery ?? routeConfig . get ( ) . mergeQuery )
84- ? { ...routeConfig . get ( ) . queryParams . data , ...navigateParams . query }
85- : ( navigateParams . query ?? { } ) ;
86-
8782 if ( typeof to === 'string' ) {
88- href = ` ${ to } ${ buildSearchString ( query ) } ` ;
83+ href = buildUrl ( to , navigateParams ) ;
8984 } else {
90- href = ( to as AnyRoute ) . createUrl ( params , query ) ;
85+ href = ( to as AnyRoute ) . createUrl (
86+ params ,
87+ navigateParams . query ,
88+ navigateParams . mergeQuery ,
89+ ) ;
9190 }
9291 }
9392
You can’t perform that action at this time.
0 commit comments