- Published on
Fixing the Unexpected use of 'location' error
- Authors
- Name
- hwahyeon
This error is caused by ESLint's no-restricted-globals
rule. This rule discourages the direct use of global variables like location
, event
, and name
to prevent unintended use of global variables in projects such as React.
Since location
is a property of the browser's global object (window
), declaring a variable with the same name in your code may unintentionally hide the global location object. This is known as a name shadowing issue.
To resolve this, use window.location
instead of location
.