一键导入
solid-router-components
Solid Router components: A for links, Route for route config, Router for setup, Navigate for redirects, active states, soft navigation.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Solid Router components: A for links, Route for route config, Router for setup, Navigate for redirects, active states, soft navigation.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
SolidJS advanced components: SuspenseList for coordinating multiple Suspense boundaries, NoHydration for skipping hydration of static content.
SolidJS advanced utilities: createRoot for manual disposal, createUniqueId for SSR-safe IDs, useTransition for batching async updates, observable for RxJS interop, modifyMutable for batch updates.
SolidJS control flow: Show for conditionals, Switch/Match for multiple conditions, For/Index for lists, Dynamic for dynamic components, Suspense for async data.
SolidJS advanced JSX attributes: @once for static values, attr:*/bool:*/prop:* for Web Components, textContent for text nodes, innerHTML for raw HTML.
SolidJS lifecycle: onMount for DOM access after mount, onCleanup for resource disposal, effect lifecycle management, component vs effect cleanup.
Core SolidJS primitives: signals use getter functions count(), components run once (no re-renders), effects track automatically, stores use direct property access, memos for computed values. Fine-grained reactivity means targeted DOM updates.
基于 SOC 职业分类
| name | solid-router-components |
| description | Solid Router components: A for links, Route for route config, Router for setup, Navigate for redirects, active states, soft navigation. |
| metadata | {"globs":["**/routes/**/*","**/*router*"]} |
Complete guide to Solid Router components. Use these components for navigation, routing setup, and redirects.
The <A> component provides enhanced anchor tags with automatic base path support, active states, and soft navigation.
import { A } from "@solidjs/router";
function Navigation() {
return (
<nav>
<A href="/">Home</A>
<A href="/about">About</A>
<A href="/contact">Contact</A>
</nav>
);
}
<A href="/users" activeClass="active" inactiveClass="inactive">
Users
</A>
Default behavior:
active class when href matches current locationinactive class otherwise/users matches /users/123)<A href="/" end>
Home
</A>
end prop:
true: Only active when exact matchfalse: Active for descendants (default)/| Prop | Type | Description |
|---|---|---|
href | string | Route path (relative or absolute) |
noScroll | boolean | Disable scroll to top on navigation |
replace | boolean | Replace history entry (no back button) |
state | unknown | Push state to history stack |
activeClass | string | Class when link is active |
inactiveClass | string | Class when link is inactive |
end | boolean | Exact match only (no descendants) |
Both <A> and <a> support soft navigation when JavaScript is present. To disable:
<A href="/page" target="_self">Link</A>
Configure routes with preloading and other options.
import { Route } from "@solidjs/router";
<Route path="/users/:id" component={UserProfile} />
<Route
path="/users/:id"
component={UserProfile}
preload={({ params }) => {
void getUserQuery(params.id);
}}
/>
| Prop | Type | Description |
|---|---|---|
path | string | Route path pattern |
component | Component | Component to render |
preload | function | Preload function |
Set up the router with base path and root component.
import { Router, A } from "@solidjs/router";
import { FileRoutes } from "@solidjs/start/router";
import { Suspense } from "solid-js";
function App() {
return (
<Router
root={(props) => (
<>
<nav>
<A href="/">Home</A>
<A href="/about">About</A>
</nav>
<Suspense>{props.children}</Suspense>
</>
)}
>
<FileRoutes />
</Router>
);
}
<Router base="/app">
<FileRoutes />
</Router>
Base path:
<A> components respect base<a> tags don't| Prop | Type | Description |
|---|---|---|
base | string | Base path for all routes |
root | Component | Root component wrapper |
data | object | Router data |
Redirect to a route programmatically.
import { Navigate } from "@solidjs/router";
function Redirect() {
return <Navigate href="/home" />;
}
<Navigate href="/home" replace />
<Navigate href="/home" state={{ from: "/login" }} />
function ProtectedRoute() {
const isAuthenticated = useAuth();
return (
<Show when={isAuthenticated()} fallback={<Navigate href="/login" />}>
<ProtectedContent />
</Show>
);
}
function Navigation() {
return (
<nav>
<A href="/" end activeClass="active">
Home
</A>
<A href="/about" activeClass="active">
About
</A>
<A href="/contact" activeClass="active">
Contact
</A>
</nav>
);
}
function Breadcrumbs() {
const location = useLocation();
const path = location.pathname.split("/").filter(Boolean);
return (
<nav>
<A href="/">Home</A>
<For each={path}>
{(segment, index) => (
<>
<span> / </span>
<A href={`/${path.slice(0, index() + 1).join("/")}`}>
{segment}
</A>
</>
)}
</For>
</nav>
);
}
function ProtectedRoute({ children }) {
const isAuthenticated = useAuth();
return (
<Show when={isAuthenticated()} fallback={<Navigate href="/login" />}>
{children}
</Show>
);
}
<Route
path="/users/:id"
component={UserProfile}
preload={({ params }) => {
void getUserQuery(params.id);
}}
/>
Use <A> for navigation:
Wrap router with Suspense:
Use end prop for root:
/ matching everythingPreload route data:
Use Navigate for redirects: