Display links with theme styles


Anchor is a wrapper around Text component with component prop set to a by default:

<Anchor href="" target="_blank">Mantine docs</Anchor>

Usage with react-router and other libraries

You can use Anchor with react-router Link component and other similar components by setting component prop:

import { Link } from 'react-router-dom';
import { Anchor } from '@mantine/core';
function Demo() {
return (
<Anchor component={Link} to="/react-router">
React router link

Usage with Next Link

Next Link component requires ref prop usage, however all Mantine components use elementRef, to make Anchor and other similar components work with Next Link, create wrapper component in your components folder:

// This component can be reused in every Mantine component which supports component pass through
import React, { forwardRef } from 'react';
import Link from 'next/link';
export const NextLink = forwardRef(
{ href, ...others }: React.ComponentPropsWithoutRef<typeof Link>,
ref: React.ForwardedRef<HTMLAnchorElement>
) => (
<Link href={href}>
{/* eslint-disable-next-line jsx-a11y/anchor-has-content */}
<a {...others} ref={ref} />

And then pass it to Button or other component:

<Anchor component={NextLink} href="/hello">
Next Link
Build fully functional accessible web applications with ease
Your feedback is most valuable contribution to the project, please share how you use Mantine, what features are missing and what is done good
Leave feedback