
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
Universal expressive routing for Node.js (Express) and Browser environments. Laravel-inspired syntax with nested layouts, middleware, and SWR support.
Universal Frontend & Backend Advanced Routing System
Re-Router is a powerful, expressive routing solution designed to work seamlessly across both Node.js (Express) and Browser environments. It brings Laravel-inspired expressive syntax, nested layouts, and advanced middleware capabilities to the JavaScript ecosystem.
npm install re-router
const { Router } = require('re-router/server');
const router = new Router();
router.get('/', () => 'Welcome Home').as('home');
router.get('/users/:id', (ctx) => {
return `Viewing User ${ctx.params.id}`;
}).as('users.show');
// Start your Express server and integrate...
Organize Your routes with prefixing and middleware application.
router.group((r) => {
r.get('/dashboard', () => 'Admin Dashboard');
r.get('/settings', () => 'Settings Page');
}).prefix('admin').middleware([authMiddleware]);
Define a chain of components that wrap your page content.
router.group((r) => {
r.group((sub) => {
sub.get('/stats', () => 'Stats Component').as('dashboard.stats');
}).prefix('dashboard').layout('DashboardLayout');
}).layout('RootLayout');
// Matches '/dashboard/stats' -> Chain: [RootLayout, DashboardLayout, 'Stats Component']
Generate standard CRUD routes for a controller.
const UserController = {
index: (ctx) => 'User List',
show: (ctx) => `User ${ctx.params.id}`,
store: (ctx) => 'User Created'
};
router.resource('users', UserController);
Protect your routes with ease using middleware, guards, or granular authorization.
router.get('/profile/:id', () => 'Profile')
.beforeEnter((ctx) => {
if (!isLoggedIn) return '/login'; // Redirect
return true; // Proceed
})
.can('update-profile') // Authorization check
.middleware([loggerMiddleware]);
Enforce specific formats for your route parameters using regex or built-in helpers.
router.get('/users/:id', () => 'User Profile')
.whereNumber('id') // Only matches if 'id' is a number
router.get('/posts/:slug', () => 'Post')
.where('slug', /^[a-z0-9-]+$/); // Custom regex
Validate incoming data for params, query, or body.
router.post('/register', () => 'User Registered')
.validate({
body: {
email: 'required|email',
password: 'required|min:8'
}
});
Bind parameters to specific resolvers for automatic data fetching.
router.bind('user', async (id) => {
return await Database.users.find(id);
});
router.get('/users/:user', (ctx) => {
// ctx.params.user is now the full user object!
return `Hello, ${ctx.params.user.name}`;
});
Pre-fetch data before the route renders.
router.get('/posts/:slug', () => 'PostContent')
.loader(async (ctx) => {
return await fetchPost(ctx.params.slug);
});
Optimize bundle size by loading handlers on demand.
router.get('/heavy-page', () => import('./LargeComponent')).lazy();
Generate URLs dynamically using route names, handling parameters and query strings automatically.
router.get('/users/:id/posts/:post_id', (ctx) => {}).as('users.posts.show');
// Generate: /users/42/posts/101
const url = router.makeUrl('users.posts.show', { id: 42, post_id: 101 });
// With Query Strings: /search?q=re-router
const search = router.makeUrl('search', {}, { qs: { q: 're-router' } });
Intercept navigation at various points in the route lifecycle.
router.get('/editor', (ctx) => 'Editor content')
.beforeEnter((ctx) => console.log('Entering...'))
.afterEnter((ctx) => console.log('Entered!'))
.beforeLeave((ctx) => {
if (hasUnsavedChanges) return false; // Cancel navigation
});
Define localized paths for the same route in one go.
router.get({
en: '/about-us',
fr: '/a-propos',
es: '/sobre-nosotros'
}, (ctx) => 'Company Info').as('about');
// router.makeUrl('about', { locale: 'fr' }) -> /a-propos
Handle errors gracefully on a per-route basis.
router.get('/api/data', () => { throw new Error('API Fail'); })
.catch((err, ctx) => {
return ctx.send({ error: 'Data unavailable' }, 500);
});
Synchronize data between backend and frontend seamlessly.
router.setApi('https://api.example.com');
router.get('/users', async (ctx) => {
// ctx.apiResponse is automatically populated from the backend
return ctx.viewHtml('users.html', { users: ctx.apiResponse.data });
});
Automatically discover routes based on your file structure, Next.js style.
// With Vite's glob import
const pages = import.meta.glob('./pages/**/*.js', { eager: true });
router.discover(pages);
// Bracket syntax for dynamic segments: ./pages/users/[id].js → /users/:id
// Catch-all routes: ./app/blog/[...slug]/page.js → /blog/*slug
// Grouped layouts: ./pages/(auth)/layout.js → wraps all auth pages
Re-Router can handle navigation in the browser using the UniversalAdapter.
const { Router } = require('re-router/server');
const Adapter = require('re-router/client');
const router = new Router();
// ... define routes ...
const adapter = new Adapter(router);
adapter.listen((chain, params) => {
// Render your UI based on the component chain
console.log('Rendering Chain:', chain);
});
// Navigate programmatically
adapter.navigate('/dashboard/settings');
MIT © Saladin Jake
FAQs
Universal expressive routing for Node.js (Express) and Browser environments. Laravel-inspired syntax with nested layouts, middleware, and SWR support.
We found that rex-router demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.