Nested wildcard routes
UniversalRouter example
by Vladimir Kutepov
HTML
<script src="https://unpkg.com/[email protected]/universal-router.min.js"></script>
Babel + JSX
// window.location
const location = new URL('https://example.com/news/section');
// routes
const route = {
path: '/news',
children: [
{
path: '/',
action() {
return 'news list';
},
},
{
path: '*',
action({ path }) {
return `news for ${path}`;
},
},
],
};
// https://github.com/kriasoft/universal-router
UniversalRouter.resolve(route, location.pathname).then(result => {
document.body.textContent = result;
});