React | React-Router, location에 state가 있네?

엄문주·2022년 6월 26일
1

Intro 🌼

음... 1년동안 개발했는데, 처음 알았다. 반성하게 되었다. history안에 location 안에 state가 있다는 걸을...
쩝...

pathname - (string) The path of the URL
search - (string) The URL query string
hash - (string) The URL hash fragment
state - (object) location-specific state that was provided to e.g. push(path, state) 
		when this location was pushed onto the stack. Only available in browser and memory history.

문제의 발생은 이렇다.
페이지 내에 있는 목록버튼을 클릭했을 때, 그 이전페이지로 넘어가게 해야하는 상황이었다. 근데, 그 페이지를 접근하는 경우가 2가지 이상이기 때문에 단순히 history.pushpath를 넣거나, history.go(-2)를 할 경우에 문제가 생길수 있는...

근데, 울 팀원이 history.location.state가 있다고...
그래서 이렇게 처리하면 될 것 같다고...
const { from } = history.location.state
history.push(from)
아...

결론 🙇

역시 개발은 팀웍이야 ㅋㅋㅋ
문제는 오픈하고 짱구를 같이 굴리면 뭐든지 해결할 수 있다~

profile
세상과 소통을 꿈꾸는 개발자

0개의 댓글