First import useRouter and useState.
import { useRouter } from "next/router";
import { useState } from "react";
In function
const share = useRouter();
const base = "http://localhost:3000";
const links = base + share.asPath;
const copylink = (e) => {
navigator.clipboard.writeText(links)
}
In Html
<div onClick={copylink} className="shareicon" >
<p> Copy to CLipboar </p>
</div>
Top comments (3)
Easy and right on time, tks
Are you sure, it works in nextjs 13+ app routing??
I'm not sure of v13