Search code examples
reactjsnode.jsnext.jsrouternextjs-dynamic-routing

How to open a link via "router.push" in a new tab using Nextjs router from next/navigation


I am developing a Nextjs app and would want to direct user to another link using router.push but I do not know how to open the link in new tab.

My code is like this right now:

import { useRouter } from "next/navigation";

const router = useRouter();

 <Button
          onClick={() => {
            router.push(`${mylink}`);
          }}
        >
          Order
</Button>

Solution

  • Router.push is meant to be used to continue on the same tab to upload new content to that page. Try using window.open('www.yourdomain.com', '_blank'); instead.