Ad

How Do I Determine If A New ReactJS Session And/or Browser Session Has Started?

- 1 answer

Each time a user navigates to an URL I plan on storing the "lastUrl" in localStorage. When they return to the site, under some conditions which are not important, I want to immediately transition them to the lastUrl that they were visiting.

I'm using ReactJS but not sure if the solution would be ReactJS specific or just using standard Browser APIs.

Is there a Browser API or ReactJS specific pattern for doing this?

This Q&A seems flaky: How to determine if the browser session just started or if it's a subsequent click?

Ad

Answer

Depending on what counts as a "session" in your app, you could use sessionStorage instead - one of the key things is that a new tab counts as a new session for sessionStorage.

Ad
source: stackoverflow.com
Ad