next/router is a library provided by Next.js. Use this tag if you need help with the useRouter hook, the withRouter HOC, or with the extracted information from the router object.
Questions tagged [next-router]
293 questions
1
vote
1 answer
NextJS redirect to other page without query params
I am able to successfully redirect the user on successful login to the relative dashboard page. However, the URI is pretty polluted in this case 'somedomain.com/v1/internal/salesman/dashboard?name=SomeName&email=someemail&uid=somenumber'. I was…

Elvin Jafali
- 113
- 2
- 13
1
vote
1 answer
Dynamic routing using Next.js
Hello I am having an issue using some dynamic routes with Next.js. My file is called [type].js. Inside this file I have the following code:
import React from 'react';
import AuthSection from 'components/AuthSection';
import { useRouter } from…

theKid
- 522
- 6
- 19
1
vote
1 answer
Next.js: How to clear browser history with Next Router?
I created a wrapper for the pages which will bounce unauthenticated users to the login page.
PrivateRoute Wrapper:
import { useRouter } from 'next/router'
import { useUser } from '../../lib/hooks'
import Login from '../../pages/login'
const…

Antonio Pavicevac-Ortiz
- 7,239
- 17
- 68
- 141
1
vote
2 answers
Next.js useRouter with useEffect pushes even if condition is met on page refresh
I am running into an issue with useRouter and useEffect where I want to re-direct the user if a certain condition is not met.
On page 1 you select an amount which is passed into a context and is retrieved on page 2.
On page 2 I have this…

Mark
- 731
- 2
- 10
- 29
1
vote
0 answers
How to have a useEffect that uses `router.push` and should only fire for `router.query.id` changes in a Next.js project
I need to transition between 2 routes in a NextJs app like the one on the following example:
FROM: /some-route?id=ID_1
TO: /some-route?id=ID_1&page=2
And I have a useEffect that does something like this:
Should fire for any id change
Makes use…

cbdeveloper
- 27,898
- 37
- 155
- 336
1
vote
1 answer
Routing in next.js
When I execute my program, it shows me this error:
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the…

Marinheiro
- 27
- 4
1
vote
1 answer
How to switch back to the default locale in Next.js?
In the Next.js app, I am using the next-i18next module for multi-language which is working fine. There are two languages one English and the other Arabic. Default is English.
For toggle, I am using the following code in NavBar.
import { useRouter}…

Deep Kakkar
- 5,831
- 4
- 39
- 75
1
vote
0 answers
next.js shallow routing different pages
I want to add routes to my next Project, but can't use shallow-router for different pages.
For example, I want to switch from /s/:id to /p/:id, without re-Render the page, just like I'm still at the same URL.
My project is already built, and I only…

Eylon Shmilovich
- 354
- 1
- 4
- 11
1
vote
0 answers
Next router allow page reload, but prevent from navigating by typing url manually
I have a multistep form, with user inputs in my second step. So, if the network crashes or for whatever reason user would need to reload this second step with the inputs, I want him to be able to do so, without being led to the default route.…

Katharina Schreiber
- 1,187
- 2
- 11
- 38
1
vote
1 answer
How to protect to access unauthenticated static page in next js directly through url?
I want to navigate to a Page only through button click on some other page and not through typing direct url route in browser in Next JS. Page is static and unauthenticated.

Rafa
- 153
- 1
- 9
1
vote
2 answers
How to allow redirect in Next.js only after reCaptcha
I have a Next.js app, index page contains only captcha, and after successfull entry redirects to form at mydomain.com/form and that works just fine.
But also i can just enter in browser
mydomain.com/form
and get to it without captcha, which i…

George Rykunov
- 11
- 4
1
vote
1 answer
How to go back to previous page in Next.js using `next/router`?
I'm using Next.js for my application and I'm facing some issues on routing to the previous route of the application. I'm aware of the router function back() which is similar to window.history.back(), I would like to go back to the route when a Link…

Aadhit Shanmugam
- 433
- 1
- 10
- 23
1
vote
0 answers
Disable Specific Paths for Next.JS File System Routing
Using project with Next.JS 9.1.2 with default server and file system routing.
I am wondering if it is possible to customize the file system routing to ignore certain paths.
Specifically, I want my directory structure under /pages/import to have a…

jjspierx
- 310
- 3
- 15
1
vote
3 answers
How to redirect if the param is not present Next.JS
I have page which can have one of 2 params. email and hash if there are not present I want to redirect the user.
/confirm-email?email=user@email.com
I have tried the following:
const router = useRouter();
const { email, hash } =…

Xaarth
- 1,021
- 3
- 12
- 34
1
vote
1 answer
How to redirect to root if the query param is not defined?
I wanna to redirect my website to the home / if the is no query param is defined. I am building a search website with nextjs is which / is the home and /search is the search page. I am passing the query term in the URL as /search?query=myterm. when…

Jemshith T K
- 87
- 4