diff --git a/examples/active-class-name/components/ActiveLink.js b/examples/active-class-name/components/ActiveLink.js index 2c561338a36a2..0db59b6a9227a 100644 --- a/examples/active-class-name/components/ActiveLink.js +++ b/examples/active-class-name/components/ActiveLink.js @@ -8,8 +8,11 @@ const ActiveLink = ({ children, activeClassName, ...props }) => { const child = Children.only(children) const childClassName = child.props.className || '' + // pages/index.js will be matched via props.href + // pages/about.js will be matched via props.href + // pages/[slug].js will be matched via props.as const className = - asPath === props.href + asPath === props.href || asPath === props.as ? `${childClassName} ${activeClassName}`.trim() : childClassName diff --git a/examples/active-class-name/components/Nav.js b/examples/active-class-name/components/Nav.js index 32e15a23466c2..2c710bb42468f 100644 --- a/examples/active-class-name/components/Nav.js +++ b/examples/active-class-name/components/Nav.js @@ -22,6 +22,11 @@ const Nav = () => ( About +
  • + + Dynamic Route + +
  • ) diff --git a/examples/active-class-name/pages/[slug].js b/examples/active-class-name/pages/[slug].js new file mode 100644 index 0000000000000..0f8f73e5888d0 --- /dev/null +++ b/examples/active-class-name/pages/[slug].js @@ -0,0 +1,14 @@ +import { useRouter } from 'next/router' +import Nav from '../components/Nav' + +const SlugPage = () => { + const { asPath } = useRouter() + return ( + <> +