generateUrl()

Generates a URL for a specified page reference.

Properties 

Method InputTypeRequired/OptionalDescription
contextStringRequiredThe ID of the parent router container nearest to the component that’s generating a URL. A ContextId is an opaque value that you get from the NavigationContext wire.
pageReferenceStringRequiredThe PageReference value for which to generate a URL.

Syntax 

1import { LightningElement, api, wire } from 'lwc';
2import { NavigationContext, generateUrl } from 'lwr/navigation';
3import type { ContextId, PageReference } from 'lwr/navigation';
4
5generateUrl(
6    context: ContextId,
7    pageReference: PageReference
8    ): string | null

Returns 

  • If pageReference is valid, generateUrl() returns a string with the generated URL for the specified route.
  • If pageReference is invalid, it returns null.
  • If context is invalid, generateUrl() fails.

See Also

Developer Preview Feature

Feature is available as a developer preview. Feature is not generally available unless or until Salesforce announces its general availability in documentation or in press releases or public statements. All commands, parameters, and other features are subject to change or deprecation at any time, with or without notice. Do not implement functionality developed with these commands or tools.

DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!