Target Active Link when the route is active in Next.js
问题 How to target the active Link in Next.js like they way we do it in React-Router-4? Meaning, give the active link a class when its route is active? 回答1: First, you need to have a component called Link, with temporary attribute activeClassName import { withRouter } from 'next/router' import Link from 'next/link' import React, { Children } from 'react' const ActiveLink = ({ router, children, ...props }) => { const child = Children.only(children) let className = child.props.className || null if