Next.js: Get previous page url

Created on 12 Jan 2018  路  3Comments  路  Source: vercel/next.js

Hi, is there a way to get the url of the previous page for page tracking purposes? window.document.referrer always points to the url in which the first page load occurred for subsequent client side page navigation.

Most helpful comment

@junshengpierre you need to implement it yourself, you can save each URL after the page changed in-memory, if you're using Redux you can dispatch an action and save the URL.

All 3 comments

Do you mean something like this?

https://github.com/zeit/next.js/blob/master/lib/router/router.js#L108

You can use Router.back() or you can even call window.history.back() like Router.back() does

Hey, @MFCo I would like to retrieve the url or pathname without navigating to the page. Do you know if that's possible?

@junshengpierre you need to implement it yourself, you can save each URL after the page changed in-memory, if you're using Redux you can dispatch an action and save the URL.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YarivGilad picture YarivGilad  路  3Comments

flybayer picture flybayer  路  3Comments

irrigator picture irrigator  路  3Comments

jesselee34 picture jesselee34  路  3Comments

wagerfield picture wagerfield  路  3Comments