예제
실용적인 예제와 라이브 데모.
예제를 선택하면 라이브 미리보기와 소스 코드를 나란히 표시하는 전체 화면이 열립니다.
예제를 선택하면 라이브 미리보기와 소스 코드를 나란히 표시하는 전체 화면이 열립니다.
프레임 안에서 자체 라우터로 돌아가는 진짜 앱입니다. 라우트 테이블, outlet() 하나, 평범한 링크, 대기 상태, 404까지 갖췄습니다. 이리저리 둘러본 뒤 뒤로 가기도 눌러 보세요.
nuclo-router는 nuclo에 포함되어 있지 않으므로 따로 설치해야 합니다:npm install nuclo nuclo-router// routes.ts: isomorphic, imported by the browser (and a server, with SSR) import { createRouter } from "nuclo-router"; import { announce } from "./embed.ts"; import { refreshSidebar } from "./sidebar.ts"; export const router = createRouter( { "/": () => import("./pages/Home.ts"), // A nested table: Docs is the layout, a topic renders in its outlet(). "/docs": { "/": () => import("./pages/Docs.ts"), "./:topic": () => import("./pages/Topic.ts"), }, // Another nested table: Shop and its section both have load()s. They run // in parallel on a cold navigation; one router.pending covers the pair. "/shop": { "/": () => import("./pages/Shop.ts"), "./:section": () => import("./pages/Section.ts"), }, "/blog/:slug": () => import("./pages/Post.ts"), // has a load() // The order opens ./customer as a layer. Nested, the layer's URL names the // page beneath it, so a reload or a fresh tab can put the stack back. "/orders/new": { "/": () => import("./pages/Order.ts"), "./customer": () => import("./pages/NewCustomer.ts"), }, "*": () => import("./pages/NotFound.ts"), }, { base: "/demos/router", // the app lives under this prefix onNavigate: (ctx, kind) => { announce(kind); // The sidebar has a router of its own, never started. Every navigation // hands it the new URL to resolve against its table and reload from. refreshSidebar(ctx.url); }, }, );