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
2 answers
Next.js routing: pushing a new route from a slug page doesn't route properly
Let's say I have 2 routes: /video and /products/[id], so my pages folder contains video.js and products/[id].js. When I use router.push or Link to navigate to /video from /products/[id], the URL gets updated to /products/video. Obviously this is not…

SkyPower
- 103
- 2
- 13
1
vote
3 answers
How to make a reset password form route with next.js
Please see EDIT below.
I am stuck with a reset password problem in my project. I am able to send an email to the user with the link for resetting the password with an hashed token and the id of the user inside.
99% of the code is already done…

msorr95
- 81
- 1
- 10
1
vote
1 answer
How to listen to changes in router and force to a class component to re-render?
Working with the framework Next.js and a class component, I'm trying to get the actual query in order to update the DOM. I'm getting the router using next/router but it return the previous one, not the actual url. Here is an example:
When the user…

CoronelV
- 357
- 1
- 2
- 14
1
vote
1 answer
How do I route with query string params in Next.js?
I have a URL like
bar?id=foo
If I route to this via router.push('bar?id=foo') everything works fine.
But if I go direct to the route in the browser, the query string does not get passed through.
const BarComponent = ()=>{
…

Dan
- 29,100
- 43
- 148
- 207
1
vote
1 answer
Next.js: Links inside dropdown menu not working
I'm trying to enable language selection in Next.js via a dropdown menu. If the links aren't nested inside the select tag, they're working fine. As soon as they are though, they're not responding anymore. I'm assuming this is because of a missing…

stevefrenzel
- 25
- 1
- 5
1
vote
0 answers
Next.js routing works forward but has problem backward
I have difficulties to understand how the next.js routing works and I think I'm using it wrong.
When I navigate forward through the pages with Link, I have no problem, but when I use the browser back button it sometimes reload the previous page and…

Rom-888
- 681
- 2
- 9
- 30
1
vote
1 answer
Next/router nothing happens when browser’s back button click
I don't understand why, when I click on browser’s back button my page doesn't reload.
I have a catalog component inside /pages/index.js which is my home page, a dynamic route to navigate to the products /pages/books/[name].js
This is the Link I use…

Rom-888
- 681
- 2
- 9
- 30
1
vote
1 answer
Next.js router locale issue
I have set up some locales for our app which are uk and us. For the blog we can have either us/blog or just /blog for the uk locale.
When I switch to us like so: (locale = "us")
const handleRoute = (locale) =>…

Aessandro
- 5,517
- 21
- 66
- 139
1
vote
3 answers
Multiple routes from single page in NextJs
I'm building a marketing/consumer site for my company, migrating away from WordPress (thank god) to a combo of Next and Prismic. Currently, our consumer site has about 600 pages to account for multiple product and landing pages for each of our 35+…

Jesse Winton
- 568
- 10
- 33
1
vote
2 answers
Next.js router create query string and query string array
I use Next.js on my project and I need to make a dynamic query string. I use this code:
const createQuery = (filter) => {
let currentPath = router.pathname;
let filterSize = Object.keys(filter).length;
filterSize != 0 ? (currentPath += "?") :…

Mustafa Uysal
- 173
- 2
- 5
1
vote
1 answer
NextJS router.push weird link
https://i.stack.imgur.com/wL0gx.jpg
When i try to redirect to home page after a login (or redirect to login after trying to access page without tokens) this url gets all weird.
How can i prevent that and have a normal path in the url?
router.push({
…

MantzarisVas
- 93
- 2
- 9
1
vote
1 answer
Next.js Add slug/params to clean URL
I have a structure with a clean URL in the "pages" folder like this ...
/pages/items/[pageNumber]/index.tsx
And if I use router.push I use it like this to get to that page ...
router.replace("/items/[pageNumber]", "/items/1")
That works great, but…

Ruby
- 2,207
- 12
- 42
- 71
1
vote
1 answer
Bug about Nextjs routing
Firstly, On development time (yarn dev), there is no routing issue. After app is deployed (npm build, export and deploy) to firebase, reload page or trying directly open page, caused response 404 not found page although it's existing. Suppose that…

forever_software
- 145
- 1
- 15
1
vote
0 answers
NextJS query only accessible via param String, not via Router.push - option
The issue I am having is regarding passing parameters from one page to another.
I have two components: Registration and Success.
Inside my Registration Component, if the user successfully registers, he will be redirect to the Success Component.…

Leviathan
- 644
- 1
- 15
- 30
1
vote
2 answers
In NextJS Is it possible to have custom _app.js read a slug, getInitialProps and pass those props to every component including all pages?
I have looked around the docs to see if I can have _app.js read a slug (nothing mentioned about it). I need this slug to be added to an HTTP get request to grab the proper data that then then returns results to _app.js in which I can then use to…

Tyler
- 63
- 2
- 9