🔀Integration with routing libs
Like react-router or Next.js file system based route.
Depending on the framework or routing library you are using, links between pages are not handled the same way.
Usually, you'll have a <Link /> component provided by your routing library of choice. You need to let react-dsfr know about it so that whenever a link is needed in a DSFR component, you can provide the correct props for your <Link /> component.
When registering your Link component, its props type will propagate to the react-dsfr API.
Follow the setup described in the getting started section:
Usage Examples
Client side routing
The <Link /> component from react-router will be used.
External links:
When react-dsfr detects that the href points to an external website it will use a regular <a/> instead of the <Link /> component.
Mailto links
Same goes for the mailto links.
Converting a link to a button
React-dsfr will automatically convert the underlying HTML element into a <button /> that looks like a link for better Accessibility.
Example here.
Examples
Client side routing
The <Link /> component from react-router will be used.
External links:
When react-dsfr detects that the href points to an external website it will use a regular <a/> instead of the <Link /> component.
Mailto links
Same goes for the mailto links.
Converting a link to a button
React-dsfr will automatically convert the underlying HTML element into a <button /> that looks like a link for better Accessibility.
Due to the fact that @tanstack/react-router is also implementing module augmentation it's just a tiny bit less straight forward to set up but it works great!
After that you will have type safety on the linkProps, you can use the to property as you would on the react router's <Link /> component!
Note that if you want to link to external website (or use mailto:) you can use the href property instead of the to property (see below).

If you have a link that is a mailto: or a link to an external page, use the href property instead of to. Example:
type-route unlike most routing library doesn't export a <Link /> component, <a /> are used directly.
In consequence there isn't anything to setup.
Examples
Client side routing
Example here.
If you are starting a new project you might want to use TanStack Router in place of react-router as it is, at least in my opignion a much better routing library.
Everywhere a DSFR component accepts a xxxLinkProps you are expected to provide an object with a to property because react-router's<Link /> component expects a to prop instead of the typical href.
You can find an example here.
Examples
Client side routing
The <Link /> component from react-router will be used.
External links:
When react-dsfr detects that the to points to an external website it will use a regular <a/> Instead of the <Link /> component.
Mailto links
Same goes for the mailto links.
Converting a link to a button
React-dsfr will automatically convert the underlying HTML element into a <button /> that looks like a link for better Accessibility.
You should be able to infer what needs to be done refering to the react-router instructions.
If the library you are using doesn't export a <Link /> (like type-route for example) component, there isn't anything to do.
Last updated
Was this helpful?