Q11. What is the useRouter hook in Next.js?
A hook that allows access to the router object and perform navigation. The `useRouter` hook allows you to programmatically change routes inside **client** components.
Technical Question Bank · Peer-Reviewed
Search and filter frequently asked interview questions across technical, programming, and behavioral domains. Tailor your interview preparation by difficulty for freshers or experienced developers (79 available).
A hook that allows access to the router object and perform navigation. The `useRouter` hook allows you to programmatically change routes inside **client** components.
The `push` method adds a new entry to the browser's history stack, while `replace` replaces the current entry in the history stack. ```jsx const router = useRouter(); // ...
A feature to create API endpoints in the `pages/api` or `app/api` directory. It allow you to create custom request handlers for a given route using the Web Request and Re...
In Next.js Pages Router, the **Singleton Router** refers to the global, shared router instance exported by `next/router`: ```javascript import Router from 'next/router'; ...
By setting appropriate headers in the API route response. ```js export default function handler(req, res) { res.setHeader("Access-Control-Allow-Origin", "*"); res.setHead...
To consider security in Next.js app router, you can follow these best practices: - Use HTTPS for all requests to ensure data is encrypted in transit. - Implement authenti...
To prevent API routes from being accessed by the client, you can implement authentication and authorization checks in your API route handlers. This ensures that only auth...
By creating a `globals.css` file in the `app` directory and importing it in the `_app.js` file. ```css /* app/globals.css */ body { margin: 0; font-family: -apple-system,...
You can opt into the Edge Runtime to run API routes on the V8/edge environment. Add `export const runtime = "edge";` at the top of a route handler and use the Web `Reques...
In the App Router you can control revalidation when fetching data by passing the `next` option to `fetch`. For example, to revalidate every 10 seconds: ```js const res = ...
HireXTech uses essential storage to remember your study preferences and third-party advertising cookies via Google AdSense in compliance with GDPR. You can choose to enable essential cookies only or accept all cookies. Read our Privacy Policy.