preactjs / preact-router

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

Unwanted css files are shared between multiple routes #442

Closed MiftikCZ closed 1 year ago

MiftikCZ commented 1 year ago

first route

export default function({}) { return <> ... some code here </> }


## second route
- loads up empty `second.css` file (which is correct)
- **so the second route should be without styling BUT it has the styles from the first route (the `first.css`)**
```tsx
import "./second.css"

export default function({}) {
  return <>
     ... some code here for the second route
  </>
}

app.tsx

import './index.css' import "@fontsource/fira-sans"

render((

), document.getElementById('app') as HTMLElement)

marvinhagemeister commented 1 year ago

The preact-router package is a client side routing library. It looks and works with the history API matches what route the user is on. Because of that it has no knowledge of how you're authoring the application. It sounds like you're expecting assets to be loaded and discarded for the current route. That's functionality that is typically provided by the meta-framework or preset you're using to build your application. These know how you authored your code and can rewrite it accordingly. Posting the question there might yield more answers.