Open simonschllng opened 4 years ago
Proposing to add the locale at one place to the Link instead of each place. Use LocaleLink instead of Link where needed.
Link
LocaleLink
import Link, { LinkProps } from 'next/link' import React from 'react' import useTranslation from '../lib/useTranslation' const LocaleLink: React.FC<LinkProps> = (props) => { const { locale } = useTranslation() const localized = Object.assign({}, props, { href: `/[lang]${props.href}`, as: props.as ? `/${locale}${props.as}` : `/${locale}${props.href}` }) return <Link {...localized} /> } export default LocaleLink
I don't know why I never thought of extending the default Link component. Brilliant! I'm definitely refactoring this over the weekend.
Looks great to me! Do you want to make a pull request?
Proposing to add the locale at one place to the
Link
instead of each place. UseLocaleLink
instead ofLink
where needed.