Skip to content
With React실무 경험

How to tell a page navigation from a reload with React & TypeScript

1 min readWorkMoved from my Tistory blogRead the Korean original

I had to write logic that branches depending on whether the user reached a page in the browser by navigating to it or by reloading it.

ts
  const navInfo = performance.getEntriesByType(
    "navigation"
  )[0] as PerformanceNavigationTiming;
  
  console.log(navInfo);
  console.log(navInfo.type);

First, here is the console.log output for navInfo.

navInfo
Figure 1. navInfo

The value I used from the navInfo data is the type property.

type follows the rules below.

  • Following a link: navigate
  • Going back: back_forward
  • Reloading: reload

I plan to use this information to branch the logic.

  • #performance.getEntriesByType("navigation")
  • #React
  • #TypeScript

More in Work