해결됨: 반응하여 현재 경로 가져오기

React가 현재 경로를 얻는 주요 문제는 속도가 느릴 수 있다는 것입니다.

There is no built-in way to get the current route in React. However, you can use the router's context to get the current location, which will give you the current pathname.

const { location } = this.context.router; console.log(location.pathname); // /some/path

name

uselocation() 후크

uselocation() 후크는 컴포넌트가 루트에서 렌더링되어야 하는지 여부를 결정하는 데 사용됩니다. 구성 요소가 루트에서 렌더링되지 않아야 하는 경우 이 후크를 사용하여 대신 렌더링되어야 하는 위치를 결정할 수 있습니다.

경로를 얻는 방법

React에서 경로를 얻는 몇 가지 방법이 있습니다. 한 가지 방법은 반응 라우터를 사용하는 것입니다. 또 다른 방법은 react-router-dom을 사용하는 것입니다.

관련 게시물:

코멘트 남김