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

<Link> causes double render when used with custom history

Open bgradin opened this issue 7 years ago • 3 comments

Currently using preact-router v2.6.0

With a router configured like: <Router history="createHashHistory()">...</Router> and a link like: <Link href="/foo">Foo</Link>, the content of the router gets rendered twice.

Cause is here: a history item is pushed (causing a render), then the router is routed to the route (causing a second render).

I haven't found a straightforward way around this, but I'd love to know if I've overlooked something.

bgradin avatar Feb 13 '18 23:02 bgradin

Actually, possibly a deeper issue.

If you look here, it seems straightforward that an event listener for popState should only be added if we don't have a custom history, but in our situation we do. Somehow popState is getting bound to anyway.

bgradin avatar Feb 14 '18 00:02 bgradin

Nevermind, was able to step into preact router code, and popState is not bound. Please disregard my last comment.

bgradin avatar Feb 14 '18 17:02 bgradin

@bgradin just to clarify - are you doing <Router history="createHashHistory()">? or did you mean <Router history={createHashHistory()}>?

developit avatar May 21 '18 17:05 developit