forge
Explore
Log in

Don't you dare go Hollow

✨ wire lazy routes and mount the app

Browse files at this commit

34b37da865bd15cdfb0d7f0ed5f812c8f35ffae8Ahmet Kaan GümüşParent: 79b5dd2
  • feat
    • ✨ wire lazy routes and mount the app
Show full message
feat: ✨ wire lazy routes and mount the app

app.tsx declares the route table with per-page lazy imports so the
first paint ships only the shell plus the page in view. Everything
except /login sits behind the auth gate, unknown paths fall through
to a 404 page, and index.tsx renders the app into #root.
src/app.tsxadded+56 -0
@@ -0,0 +1,56 @@
1+// Route table. Pages are lazy so the first paint ships only the shell plus the
2+// page in view. Everything except /login sits behind the auth gate.
3+
4+import { Navigate, Route, Router } from "@solidjs/router";
5+import { Show, lazy, type ParentProps } from "solid-js";
6+import { Layout } from "./components/Layout";
7+import { Loading } from "./components/Feedback";
8+import { AuthProvider, useAuth } from "./lib/auth";
9+
10+const Login = lazy(() => import("./pages/Login"));
11+const Home = lazy(() => import("./pages/Home"));
12+const Notes = lazy(() => import("./pages/Notes"));
13+const Events = lazy(() => import("./pages/Events"));
14+const EventDetail = lazy(() => import("./pages/EventDetail"));
15+const Courses = lazy(() => import("./pages/Courses"));
16+const CourseDetail = lazy(() => import("./pages/CourseDetail"));
17+const Exams = lazy(() => import("./pages/Exams"));
18+const ExamDetail = lazy(() => import("./pages/ExamDetail"));
19+const Marks = lazy(() => import("./pages/Marks"));
20+const Profile = lazy(() => import("./pages/Profile"));
21+const Users = lazy(() => import("./pages/Users"));
22+const NotFound = lazy(() => import("./pages/NotFound"));
23+
24+/** Renders children once the session is known; bounces to /login when absent. */
25+function Protected(props: ParentProps) {
26+ const { user } = useAuth();
27+ return (
28+ <Show when={user() !== undefined} fallback={<Loading />}>
29+ <Show when={user()} fallback={<Navigate href="/login" />}>
30+ <Layout>{props.children}</Layout>
31+ </Show>
32+ </Show>
33+ );
34+}
35+
36+export function App() {
37+ return (
38+ <Router root={(props) => <AuthProvider>{props.children}</AuthProvider>}>
39+ <Route path="/login" component={Login} />
40+ <Route component={Protected}>
41+ <Route path="/" component={Home} />
42+ <Route path="/notes" component={Notes} />
43+ <Route path="/events" component={Events} />
44+ <Route path="/events/:id" component={EventDetail} />
45+ <Route path="/courses" component={Courses} />
46+ <Route path="/courses/:id" component={CourseDetail} />
47+ <Route path="/exams" component={Exams} />
48+ <Route path="/exams/:id" component={ExamDetail} />
49+ <Route path="/marks" component={Marks} />
50+ <Route path="/profile" component={Profile} />
51+ <Route path="/users" component={Users} />
52+ </Route>
53+ <Route path="*" component={NotFound} />
54+ </Router>
55+ );
56+}
src/index.tsxadded+6 -0
@@ -0,0 +1,6 @@
1+/* @refresh reload */
2+import { render } from "solid-js/web";
3+import { App } from "./app";
4+import "./styles.css";
5+
6+render(() => <App />, document.getElementById("root")!);
src/pages/NotFound.tsxadded+13 -0
@@ -0,0 +1,13 @@
1+import { A } from "@solidjs/router";
2+
3+export default function NotFound() {
4+ return (
5+ <main class="auth-page">
6+ <div class="card stack" style={{ "text-align": "center", padding: "2.5rem 3rem" }}>
7+ <h1 style={{ "font-size": "2.5rem" }}>404</h1>
8+ <p class="muted">This page flew away.</p>
9+ <A href="/">Back home</A>
10+ </div>
11+ </main>
12+ );
13+}