How to tackle redirect to an external url in NextJS?

The latest version of Next.js has this built in using the next.config.js script (see https://nextjs.org/docs/api-reference/next.config.js/redirects). No need for additional plugins. To test, copy the NextJs sample app: npx create-next-app nextjs-blog –use-npm –example “https://github.com/vercel/next-learn-starter/tree/master/learn-starter” Add a next.config.js file to the root folder with the following code: // this simply tests the redirecting of the root path … Read more

NextJs – Link to scroll to a section in same page

In vanilla HTML you’d do something like this <a href=”#first-section”>My first section</a> <a href=”#second-section”>My second section</a> <div id=”first-section”>SECTION 1</div> <main id=”second-section”>SECTION 2</main> In NextJS you’d so something similar. Instead of using the anchor tag for linking, you’d use the Link components. <Link href=”#first-section”>My first section</Link> <Link href=”#second-section”>My second section</Link> <div id=”first-section”>SECTION 1</div> <main id=”second-section”>SECTION 2</main> … Read more

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 … Read more

nextjs – next build with NODE_ENV=development

UPDATE 2022-11-23: See how-to-set-environment-variables-from-within-package-json. In short: “start:dev”: “NODE_ENV=development next start” You might need cross-env (on Windows ? I don’t know): “start:dev”: “cross-env NODE_ENV=development next start” More specific documentation is now available (and maybe requirements also have changed, or maybe not): environment-variable-load-order: … Note: The allowed values for NODE_ENV are production, development and test. non-standard-node-env: … … Read more

The default export is not a React Component in page: “/” NextJS

Date: 23/01/2021 I’ve also faced this issue on my Next.js app. If you’re using a functional component instead of a class component you’ll get this error as well in some casses. Exactly I don’t know why this is happening but I just resolved this issue by exporting my component at the bottom of the page. … Read more

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