router.asPath shows previous URL on client side from _app.js getInitialProps
See original GitHub issueconsole.log(router)
shows correct asPath but If I access console.log(router.asPath)
shows the previous URL
- I have searched the issues of this repository and believe that this is not a duplicate.
Code (_app.js
)
export default class MyApp extends App {
constructor(props) {
super(props)
}
static async getInitialProps({ Component, router, ctx }) {
// Router.asPath shows current URL, can be seen from browser console as below
console.log(router)
// But if i access the asPath property as below, it shows previous URL. On server side, it's fine
console.log(router.asPath)
}
...
}
Expected Behavior
Refer to above code, router.asPath
should return current URL on client side
Current Behavior
Refer to above code, router.asPath
returns previous URL on client side
Steps to Reproduce (for bugs)
Please refer to above code example.
Context
After url is deprecated, we pass URL from _app.js
, as all pages need this for some sort of SEO related stuffs.
as a workaround using ctx.asPath
for now
Your Environment
Tech | Version |
---|---|
next | 6.0.0 |
node | 9.x |
OS | mac |
browser | Chrome |
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How to get previous URL in Next.js? - Stack Overflow
Actually, I want to call router.push after login. I know that router.back goes to the previous page. But it's possible to go to...
Read more >getInitialProps - Data Fetching - Next.js
getInitialProps enables server-side rendering in a page and allows you to do initial data population, it means sending the page with the data...
Read more >What is Next.js getInitialProps and getServerSideProps? | refine
getInitialProps behavior can be tricky for developers who are new to Next.js. The function runs only on the server at the initial page...
Read more >Refreshing Server-Side Props - Next.js - Josh W Comeau
Next allows you to do server-side data-fetching, but what happens when that data needs to change on the client? This brief tutorial shows...
Read more >Client-Side Routing In Next.js - Smashing Magazine
Next.js has a file-based routing system in which each page automatically becomes a route based on its file name. This article will guide...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Specifically this PR fixed it: #4541
Should be fixed in
next@canary