Anchors
Anchors are rendered with an internal renderer. See Rendering page. The content model of anchors is mixed, see Element Models.
Minimal Example
- JSX Source
- HTML Snippet
- TRT Snapshot
By default, pressing an anchor will open the link in the system browser. This is done with React Native Linking API.
Block Example
In the below example, the anchor will be translated to a TNode node, because some of its children (<img>) have a block content model. This is a feature of the mixed content model.
- JSX Source
- HTML Snippet
- TRT Snapshot
Relative URLs
The HTML standard allows relative URLs, for example when anchors have a href attribute with no origin, such as <a href="contact.html">. The new foundry release adheres closely to this standard, by extracting information about the baseUrl of the current page. Either by the mean of the <base> element, or by information contained in the source prop. Example:
- JSX Source
- HTML Snippet
- TRT Snapshot
You can use the same URL normalization mechanism in your custom renderers thanks to useNormalizedUrl hook.
Configuring
We can take advantage of the renderersProps to customize anchors behavior (see RenderersProps.a). Anchors support onPress prop to handle press events.
- JSX Source
- HTML Snippet
- TRT Snapshot