React - window is not defined issue

0 votes
75 views
added Mar 18, 2022 in React by lcjr First Warrant Officer (9,410 points)

// instead of window.location.pathname like we use for normal JS, add window && 
const current_path = window && window.location.pathname;
const path_arr = current_path.split("/");
const narrGroup = path_arr[2];

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...