I am trying to use location props in my gastby page : I am passing props in my Link in pages/index.js:
JavaScript
x
3
1
<Link state={{eventID: event.id}} to={`/date/${event.name}`}>
2
</Link>
3
pages/date/[dateId]/index.js:
JavaScript
1
5
1
const DateWithId = ({location},props) => {
2
const { state = {} } = location
3
const { eventID} = state
4
}
5
eventually I get an error Parsing error: Identifier ‘location’ has already been declareded :
Advertisement
Answer
You should have the location
variable already defined, it is likely in the global scope so you don’t need to pass it as a parameter to the function. Try just using the variable and see if that works.