@@ -207,6 +207,8 @@ class PathInfo {
207207export class RequestInfo {
208208 #request;
209209
210+ #router;
211+
210212 #pathInfo;
211213
212214 #owner;
@@ -215,8 +217,9 @@ export class RequestInfo {
215217
216218 #ref;
217219
218- constructor ( request , pathInfo ) {
220+ constructor ( request , router , pathInfo ) {
219221 this . #request = request ;
222+ this . #router = router ;
220223 this . #pathInfo = pathInfo ;
221224 }
222225
@@ -310,6 +313,7 @@ export class RequestInfo {
310313 * Create a new request info.
311314 *
312315 * @param {import('@adobe/fetch').Request } request request
316+ * @param {import('../router/router.js').default } router router
313317 * @param {object } param0 params
314318 * @param {string } [param0.org] org, optional
315319 * @param {string } [param0.site] site, optional
@@ -318,13 +322,13 @@ export class RequestInfo {
318322 * @param {string } [param0.route] route, optional
319323 * @returns {RequestInfo }
320324 */
321- static create ( request , {
325+ static create ( request , router , {
322326 org, site, path, ref, route,
323327 } = { } ) {
324328 const httpRequest = new HttpRequest ( request ) ;
325329 const pathInfo = new PathInfo ( route , org , site , path ) ;
326330
327- return Object . freeze ( new RequestInfo ( httpRequest , pathInfo ) . withRef ( ref ) ) ;
331+ return Object . freeze ( new RequestInfo ( httpRequest , router , pathInfo ) . withRef ( ref ) ) ;
328332 }
329333
330334 /**
@@ -343,6 +347,7 @@ export class RequestInfo {
343347 } ) {
344348 const info = new RequestInfo (
345349 other . #request,
350+ other . #router,
346351 PathInfo . clone ( other . #pathInfo, {
347352 org, site, path, route,
348353 } ) ,
@@ -375,6 +380,21 @@ export class RequestInfo {
375380 return url . href ;
376381 }
377382
383+ getAPIUrls ( ...routes ) {
384+ const links = { } ;
385+ const variables = {
386+ org : this . org ,
387+ site : this . site ,
388+ path : this . webPath . slice ( 1 ) ,
389+ ref : this . ref ,
390+ } ;
391+ routes . forEach ( ( name ) => {
392+ const path = this . #router. external ( name , variables ) ;
393+ links [ name ] = this . getLinkUrl ( path ) ;
394+ } ) ;
395+ return links ;
396+ }
397+
378398 toResourcePath ( ) {
379399 return toResourcePath ( this . webPath ) ;
380400 }
0 commit comments