有没有办法在 React Router v4 中为activeClassName
设置默认NavLink
,而不必为每个NavLink
设置它?
<NavLink activeClassName='active' to='/one/'>one</NavLink>
<NavLink activeClassName='active' to='/two/'>two</NavLink>
<NavLink activeClassName='active' to='/three/'>three</NavLink>
写下来会很高兴:
<NavLink to='/one/'>one</NavLink>
<NavLink to='/two/'>two</NavLink>
<NavLink to='/three/'>three</NavLink>
答案 0 :(得分:2)
制作包装纸?
const MyNavLink = ({ children, ...props }) => (
<NavLink activeClassName="active" {...props}>
{children}
</NavLink>
);
<MyNavLink to='/one/'>one</MyNavLink>