Sling Academy
Home/Next.js/Page 8

Next.js

How to Run Next.js on Custom Ports

How to Run Next.js on Custom Ports

Updated: Jan 14, 2023
By default, a Next.js app will run on port 3000 (both in the development and production environments). However, you can use another port if you like. This short and straight-to-the-point article will show you how to do so. Modifying......
How to Create a Next.js App in the Current Directory

How to Create a Next.js App in the Current Directory

Updated: Jan 14, 2023
You can initialize a new Next.js app in the current directory by using a dot (.) for the path when running the npx create-next-app command. There is a mandatory requirement is that the name of the current folder must not contain special......
Solving the ‘Window is Not Defined’ Error in Next.js

Solving the ‘Window is Not Defined’ Error in Next.js

Updated: Jan 10, 2023
This article shows you a few solutions to fix the window is not defined error in Next.js. Understanding The Problem When working with Next.js, you are likely to run into the window is not defined error at least one time in your......

How to Detect Server vs Client Environment in Next.js

Updated: Jan 10, 2023
In Next.js, you can programmatically detect between the server environment and the client environment by checking whether the window object exists or not, like this: const isServer = typeof window === 'undefined'; if(isServer){ // do......
Next.js: 2 ways to fix the ‘document is not defined’ error

Next.js: 2 ways to fix the ‘document is not defined’ error

Updated: Jan 09, 2023
When working with Next.js, you might encounter the document is not defined error. This article will explain why this error happens, then walk you through a couple of different ways to get rid of it. The Cause of the Error Next.js......
How to style Link component in Next.js

How to style Link component in Next.js

Updated: Jan 09, 2023
In Next.js, <Link> is one of the most-used components. To style it, you can use the className or the style props (in the old days, we had to add a <a> tag inside a <Link>, but now there is no need to do so). Example: JSX......

Next.js: Extracting URL params inside getStaticProps function

Updated: Jan 09, 2023
In Next.js, If a page uses a dynamic route, the params object contains the route parameters. For instance, If the page name is [id].js, then the params will look as follows: { id: /* something */ } You can get URL params from inside......
How to use SASS in Next.js

How to use SASS in Next.js

Updated: Jan 09, 2023
SASS (Syntactically Awesome Style sheets) can make your life much easier when writing CSS code with variables, nesting, mixins, and other amazing features. This succinct article shows you how to use SASS in Next.js. The Steps 1.......
Next.js: Parsing Query String Parameters

Next.js: Parsing Query String Parameters

Updated: Jan 09, 2023
In Next.js, you can get the query string parameters of a URL by using the useRouter hook like this: import { useRouter } from "next/router"; /*...*/ const router = useRouter(); const queryParams =......
Passing data via a Link component in Next.js

Passing data via a Link component in Next.js

Updated: Jan 09, 2023
This concise article is about passing and retrieving data with Link components in Next.js. We’ll discuss the technique (just a few words) and then examine a complete example of applying that technique in practice. Overview You......
Next.js: Disable Server-Side Rendering on Specific Pages

Next.js: Disable Server-Side Rendering on Specific Pages

Updated: Jan 09, 2023
There may be situations where you want to disable server-side rendering (SSR) on one or some specific pages of your Next.js application, such as you get some warnings or errors when using a third-party library due to SSR or you want a......
How to Change the Base Path in Next.js (Subdirectory Path)

How to Change the Base Path in Next.js (Subdirectory Path)

Updated: Jan 09, 2023
There might be cases where you want to deploy a complex web app that consists of multiple child web apps. Each child web app is developed independently by a team and goes with a subdirectory path like......