Examples
Practical examples। Live demos।
कोई example चुनिए और फ़ुल-स्क्रीन में खोलिए: live preview और source code साथ-साथ।
कोई example चुनिए और फ़ुल-स्क्रीन में खोलिए: live preview और source code साथ-साथ।
static, :param और *rest patterns, साथ में दो parents के नीचे लगी एक section table। path लिखकर match() देखिए: यह कुछ भी load किए बिना match करता है।
nuclo-router nuclo के साथ नहीं आता, इसे अलग से install करना होगा:npm install nuclo nuclo-routerStatic patterns win over dynamic ones, so /blog/new is not a slug. The section table is mounted under two parents with no path written twice.
// npm install nuclo nuclo-router import { createRouter, type RouteTable } from 'nuclo-router' // A reusable section: "./" patterns are relative to the parent. const recordSection: RouteTable = { '/': () => import('./Record.ts'), // the parent path itself './preview': () => import('./Preview.ts'), './preview/raw': () => import('./Raw.ts'), } const router = createRouter({ '/': () => import('./pages/Home.ts'), '/blog/new': () => import('./pages/NewPost.ts'), '/blog/:slug': () => import('./pages/Post.ts'), '/invoices/:id': recordSection, '/customers/:id': recordSection, '/files/*rest': () => import('./pages/File.ts'), '*': () => import('./pages/NotFound.ts'), }) // match() resolves a URL and loads nothing: no import, no history. router.match('/blog/new') // { pattern: '/blog/new', params: {} } static wins router.match('/blog/hello') // { pattern: '/blog/:slug', params: { slug: 'hello' } } router.match('/customers/7/preview/raw') // { pattern: '/customers/:id/preview/raw', params: { id: '7' } } router.match('/files/a/b.txt') // { pattern: '/files/*rest', params: { rest: 'a/b.txt' } } // On a server, a 404 before importing a single chunk: if (!router.match(request.url)) { return new Response(null, { status: 404 }) }