preactjs / preact-router

:earth_americas: URL router for Preact.
http://npm.im/preact-router
MIT License
1.01k stars 156 forks source link

Assets of component with path '/' are loaded on every route #403

Closed rubenpoppe closed 3 years ago

rubenpoppe commented 3 years ago

I noticed that when built, my app loads images from Home (path="/") on every other route too.

<Router>
  <Home path="/" /> {/*thumb images should be loaded*/}
  <About path="/about" /> {/*images should not be loaded*/}
  <Article path="/:slug" /> {/*images should not be loaded*/}
</Router>
Home About Article
image image image

I guess in react-router it would be solved with adding exact to the first route, but I don't know of such behavior in preact-router.

rubenpoppe commented 3 years ago

It seems the contents of Home briefly flash on the screen so it would seem more like why Switch is implemented.

rubenpoppe commented 3 years ago

It comes down to pre-rendering. Adding the prerender-urls fixes it.