Skip to content

Wildcard: refactor Link components

Warren Gifford requested to merge og/wildcard-link-refactor into main

Created by: oleggromov

Context

As previously discussed, we're simplifying Link components that we use in our codebase.

Changes

From now on, Links are structured and used like this:

<Link> - top-level, "umbrella" component for unification across different code hosts

<RouterLink> - renders Link from react-router and AnchorLink for absolute URLs, used on the web
|-- <AnchorLink>
|-- <ReactRouterLink>

<AnchorLink> - renders plain <a> elements, used on all other code hosts

Components are still supposed to be initialized with setLinkComponent at the app initialization.

Typing

To achieve compatibility between typeof AnchorLink and typeof RouterLink, which is required to use them interchangeably with setLinkComponent, we only support to: string as property and drop support for as property.

To keep support for History.LocationDescriptorObject and alike, with pathname, hash, etc, we provide a convenience method createLinkUrl. After migration to React Router V6 its contents will be replaced with the new APIs without using history directly.

Test plan

App preview:

Check out the client app preview documentation to learn more.

Merge request reports

Loading