ReactJS - (URLSearchParams(location.search).get('keyword')
렌더링된 검색 키워드를 파싱해서 출력해주기
~cra-router/src/routes$ Search.js
import React from 'react';
const Search = ({location}) => {
return (
<div>
{new URLSearchParams(location.search).get('keyword')}
검색
</div>
);
};
export default Search;
~cra-router/cra/components$ Header.js
import React from 'react';
import { NavLink } from 'react-router-dom';
import './Header.css';
const Header = () => {
return (
<div className="header">
<NavLink exact to="/" className="item" activeClassName="active">홈</NavLink>
<NavLink to="/about/boolean" className="item" activeClassName="active">소개</NavLink>
<NavLink to="/posts" className="item" activeClassName="active">포스트</NavLink>
<NavLink to="/login" className="item" activeClassName="active">로그인</NavLink>
<NavLink to="/mypage" className="item" activeClassName="active">마이페이지</NavLink>
<NavLink to="/search" className="item" activeClassName="active">검색</NavLink>
</div>
);
};
export default Header;
'my_lesson > _ReactJS' 카테고리의 다른 글
React-router - Code Splitting(prodoction) _Environment (0) | 2018.04.12 |
---|---|
React-router - NotFound (Switch) (0) | 2018.04.11 |
React-router - Redirect (0) | 2018.04.11 |
React-router - NavLink (0) | 2018.04.11 |
React-router - Add Route in route (double route) (0) | 2018.04.11 |
댓글