SolidJSS
SolidJS2y ago
46 replies
Zed

Solidjs route not working...

I am getting an error which you can see in the image and I can't see the content which I put in there.
I am using Solidjs 1.8.11 with @solidjs/router 0.13.2 and JS
My code -

Index.jsx -
import { render } from "solid-js/web";
import { Router } from "@solidjs/router";
import App from "./App";
import "./index.css";

const root = document.getElementById("root");

if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
  throw new Error(
    "Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?"
  );
}

render(
  () => (
    <Router>
      <App />
    </Router>
  ),
  root
);


App.jsx -
import { Routes, Route } from "@solidjs/router";
import Home from "./pages/home";
import About from "./pages/about";

function App() {
  return (
    <div>
      <Routes>
        <Route path="/" component={Home} />
        <Route path="/about" component={About} />
      </Routes>
    </div>
  );
}

export default App;


home.jsx -
export default function Home(){
  return (
    <div>
      <h1>Hello</h1>
    </div>
  );
}

home.jsx is in ./src/pages
while App.jsx & index.jsx are in ./src
image.png
Was this page helpful?