How to use SolidJS Routes in Astro?
I try to use solidjs route in astro project but it does not show anything. This test 1 and 2 code not give any outputs.
Test 1:
index.astro
Router.astro
Home.astro
About.astro
Test 2:
index.astro
route.jsx
App.jsx
Home.jsx and Users.jsx
Test 1:
index.astro
---
import Router from "./Router.astro";
---
<Router />
Router.astro
---
import { render } from "solid-js/web";
import { Router, Route } from "@solidjs/router";
import Home from "./Home.astro";
import About from "./About.astro";
---
<Router>
<Route path="/" component={Home} />
<Route path="/about" component={About} />
</Router>
Home.astro
<section>
<h1>Home Page</h1>
<p>This is the home page.</p>
</section>
About.astro
<section>
<h1>About Page</h1>
<p>This is the about page.</p>
</section>
Test 2:
index.astro
---
import Layout from "../../layouts/Layout2.astro";
import Route from "./route.jsx";
---
<Layout title="Welcome to Astro.">
<div id="app"></div>
<h1>Hello</h1>
<Route client:only="solid-js" />
</Layout>
route.jsx
import { render } from "solid-js/web";
import { Router } from "@solidjs/router";
import App from "./App";
export default function Counter() {
{
render(
() => (
<Router>
<App />
</Router>
),
document.getElementById("app")
);
}
return <></>;
}
App.jsx
import { Routes, Route } from "@solidjs/router";
import Home from "./pages/Home";
import Users from "./pages/Users";
export default function App() {
return (
<>
<h1>My Site with Lots of Pages</h1>
<Routes>
<Route path="/users" component={Users} />
<Route path="/" component={Home} />
<Route
path="/about"
element={<div>This site was made with Solid</div>}
/>
</Routes>
</>
);
}
Home.jsx and Users.jsx
export default function Home() {
return <div>Page</div>;
}
export default function Users() {
return <div>Page</div>;
}

