@@ -39,19 +39,41 @@ export class InternalLinkService {
3939 * @returns The relative path for the given internal link.
4040 */
4141 public getRelativePath ( link : string ) : string {
42- // Create a Domain object for the provided link
42+ // Obtaining the base URL, disregarding query parameters
43+ const baseUrl = link . split ( '?' ) [ 0 ] ;
4344 const currentDomain = new URL ( this . currentURL ) . hostname ;
4445
45- if ( link . startsWith ( this . currentURL ) ) {
46- const currentSegments = link . substring ( this . currentURL . length ) ;
46+ if ( baseUrl . startsWith ( this . currentURL ) || baseUrl . startsWith ( currentDomain ) ) {
47+ const base = baseUrl . startsWith ( this . currentURL ) ? this . currentURL : currentDomain ;
48+ const currentSegments = baseUrl . substring ( base . length ) ;
4749 return currentSegments . startsWith ( '/' ) ? currentSegments : `/${ currentSegments } ` ;
4850 }
4951
50- if ( link . startsWith ( currentDomain ) ) {
51- const currentSegments = link . substring ( currentDomain . length ) ;
52- return currentSegments . startsWith ( '/' ) ? currentSegments : `/${ currentSegments } ` ;
52+ return baseUrl . startsWith ( '/' ) ? baseUrl : `/${ baseUrl } ` ;
53+ }
54+
55+ /**
56+ * Parse the query parameters from a given URL link.
57+ *
58+ * @param link The URL link containing query parameters.
59+ * @returns An object containing the parsed query parameters.
60+ */
61+ public getQueryParams ( link : string ) : Record < string , string > {
62+ const queryParams : Record < string , string > = { } ;
63+
64+ const queryStringStartIndex = link . indexOf ( '?' ) ;
65+ if ( queryStringStartIndex !== - 1 ) {
66+ const paramsString = link . substring ( queryStringStartIndex + 1 ) ;
67+ const paramsArray = paramsString . split ( '&' ) ;
68+
69+ paramsArray . forEach ( param => {
70+ const [ key , value ] = param . split ( '=' ) ;
71+ if ( key && value ) {
72+ queryParams [ key ] = decodeURIComponent ( value . replace ( / \+ / g, ' ' ) ) ;
73+ }
74+ } ) ;
5375 }
5476
55- return link ;
77+ return queryParams ;
5678 }
5779}
0 commit comments