mirror of https://github.com/MaxLeiter/Drift
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			27 lines
		
	
	
		
			710 B
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			27 lines
		
	
	
		
			710 B
		
	
	
	
		
			TypeScript
		
	
import { useRouter } from "next/router"
 | 
						|
import NextLink from "next/link"
 | 
						|
import styles from "./link.module.css"
 | 
						|
 | 
						|
type LinkProps = {
 | 
						|
	href: string,
 | 
						|
	colored?: boolean,
 | 
						|
	children: React.ReactNode
 | 
						|
} & React.ComponentProps<typeof NextLink>
 | 
						|
 | 
						|
const Link = ({ href, colored, children, ...props }: LinkProps) => {
 | 
						|
	const { basePath } = useRouter()
 | 
						|
	const propHrefWithoutLeadingSlash =
 | 
						|
		href && href.startsWith("/") ? href.substring(1) : href
 | 
						|
 | 
						|
	const url = basePath ? `${basePath}/${propHrefWithoutLeadingSlash}` : href
 | 
						|
 | 
						|
	const className = colored ? `${styles.link} ${styles.color}` : styles.link
 | 
						|
	return (
 | 
						|
		<NextLink {...props} href={url} className={className}>
 | 
						|
			{children}
 | 
						|
		</NextLink>
 | 
						|
	)
 | 
						|
}
 | 
						|
 | 
						|
export default Link
 |