Universal Router Demo

node v8.17.0
version: 4.0.0
endpointsharetweet
const UniversalRouter = require('universal-router'); const routes = [ { path: '', // optional action: () => `<h1>Home</h1>`, }, { path: '/posts', action: () => console.log('checking child routes for /posts'), children: [ { path: '', // optional, matches both "/posts" and "/posts/" action: () => `<h1>Posts</h1>`, }, { path: '/:id', action: (context) => `<h1>Post #${context.params.id}</h1>`, }, ], }, ]; const router = new UniversalRouter(routes); router.resolve('/posts').then(html => { console.log(html); // prints: <h1>Posts</h1> });
Loading…

no comments

    sign in to comment