본문 바로가기

웹프로그래밍/React

[React.js] React Router v5, useRouteMatch 추가.

반응형

https://github.com/ReactTraining/react-router/releases/tag/v5.1.0

 

Release v5.1.0 · ReactTraining/react-router

Read the blog post List of commits Features Add useParams, useLocation, useHistory, and useRouteMatch hooks (d6224d6) Add support for forwardRef in (b5528ed) Add support for functions in <l...< p=""> </l...<>

github.com

PathVariable 을 받을 때 match 값을 hook으로 받을 수 있게 react router v5에서 추가되었다.

아래와 같이 사용하면 된다.

 

import { useRouteMatch } from 'react-router-dom';

const Component = () => {
	const { params }: any = useRouteMatch();
    
    // /path/:idx
    return (
    	<div>{params?.idx}</div>
    );
};

export default Component;
반응형