~repos /edge-city
git clone https://pyrossh.dev/repos/edge-city.git
edge-city is a next level meta-framework for react that runs only on edge runtimes
89c11a40
—
Peter John 2 years ago
add dynamic css injection
packages/example/routes/about/page.css
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
.about-page {
|
|
2
|
-
padding:
|
|
2
|
+
padding: 20px;
|
|
3
|
+
padding-bottom: 130px;
|
|
4
|
+
background-color: violet;
|
|
3
5
|
}
|
packages/parotta/router.js
CHANGED
|
@@ -10,10 +10,26 @@ const getRoute = (radixRouter, pathname) => {
|
|
|
10
10
|
return matchedPage;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
const loadCss = (pathname) => {
|
|
14
|
+
const href = `/routes${pathname === "/" ? "" : pathname}/page.css`;
|
|
15
|
+
const isLoaded = Array.from(document.getElementsByTagName("link"))
|
|
16
|
+
.map((link) => link.href.replace(window.origin, "")).includes(href);
|
|
17
|
+
if (!isLoaded) {
|
|
18
|
+
const fileref = document.createElement("link");
|
|
19
|
+
fileref.rel = "stylesheet";
|
|
20
|
+
fileref.type = "text/css";
|
|
21
|
+
fileref.href = href;
|
|
22
|
+
document.getElementsByTagName("head")[0].appendChild(fileref);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
13
26
|
export const Router = ({ App, history, radixRouter }) => {
|
|
14
27
|
const [Page, setPage] = useState(() => getRoute(radixRouter, history.location.pathname));
|
|
15
28
|
useEffect(() => {
|
|
29
|
+
return history.listen(({ location }) => {
|
|
30
|
+
loadCss(location.pathname);
|
|
16
|
-
|
|
31
|
+
setPage(getRoute(radixRouter, location.pathname));
|
|
32
|
+
});
|
|
17
33
|
}, [])
|
|
18
34
|
console.log('Router');
|
|
19
35
|
return React.createElement(RouterContext.Provider, {
|