preact-router icon indicating copy to clipboard operation
preact-router copied to clipboard

Link activeClassName not working.

Open Aurailus opened this issue 4 years ago • 8 comments

Hi, I'm trying to use ActiveClassName to style my links, but the property is not being processed, and is instead being passed down to the native DOM. Here's my code:

					<nav class="AppHeader-nav">
						<Link activeClassName="active" href="/admin/home">Home</Link>
						<Link activeClassName="active" href="/admin/pages">Pages</Link>
						<Link activeClassName="active" href="/admin/media">Media</Link>
						<Link activeClassName="active" href="/admin/themes">Themes</Link>
						<Link activeClassName="active" href="/admin/plugins">Plugins</Link>
					</nav>

And the resultant HTML:

<nav class="AppHeader-nav"><a activeclassname="active" href="/admin/home">Home</a><a activeclassname="active" href="/admin/pages">Pages</a><a activeclassname="active" href="/admin/media">Media</a><a activeclassname="active" href="/admin/themes">Themes</a><a activeclassname="active" href="/admin/plugins">Plugins</a></nav>

I as on /admin/home when I copied the above HTML. Please let me know if you need any more information.

Aurailus avatar Sep 14 '20 00:09 Aurailus

Possibly related to #365 ?

levidurfee avatar Oct 18 '20 14:10 levidurfee

Any updates on that? I have the very same issue.

mariosant avatar Jul 29 '21 13:07 mariosant

Any updates? Same problem here.

sirianni avatar Dec 20 '21 21:12 sirianni

I see the same behaviour. Link from match does not have activeClassName applied when on href route.

orangecoloured avatar Jan 18 '22 16:01 orangecoloured

As per this comment: https://github.com/preactjs/preact-router/issues/333#issuecomment-543839970, this is fixed for me if I use import { Link } from 'preact-router/match'; rather than import { Link } from 'preact-router'; (preact-router v3.2.1)

timiles avatar Apr 10 '22 15:04 timiles

The active class with Link from match doesn't work for SSR pages.

orangecoloured avatar Apr 14 '22 12:04 orangecoloured

<Link> from preact-router/src/index.js should just reexport from preact-router/match/src/index.js

qrhfz avatar Feb 10 '23 23:02 qrhfz

There is indeed bug with matching <Link> and activeClassName when className is present

import { Link } from 'preact-router/match';

<Link activeClassName="is-active" class="c-header-link" href="/foo">Foo</Link> // works

<Link activeClassName="is-active" className="c-header-link" href="/foo">Foo</Link> // does not work

Tested with [email protected] and [email protected]

teodragovic avatar Jul 03 '23 10:07 teodragovic