Location is not defined error in React + Next.js?

Can you show your imports, because it could be that you are importing router from 'next/client'

Assuming that you are using functional-based component

You need to import router as follows:

import {useRouter} from "next/router";

in your function body:

const router = useRouter();

Edit, those who’re using NextJS v13+
The router has been moved from next/router to next/navigation
https://nextjs.org/docs/app/api-reference/functions/use-router

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)