0.8.0 • Published 2 years ago
@routo/core v0.8.0
@routo/core
Simple framework-agnostic router
Install
yarn add @routo/core
Usage
import { createRouter } from '@routo/core';
const HOME = 'router/HOME';
const POST = 'router/POST';
const routes = [
{
id: HOME,
path: '/',
},
{
id: POST,
path: '/posts/:id',
},
];
const router = createRouter(routes);
const unsubscribe = router.subscribe((state) => console.log(state.pathname));
router.replace(POST, { params: { id: '42' } });
// /posts/42
unsubscribe();
State
{
id: 'router/POST',
pathname: '/posts/42',
search: '',
queryParams: {},
action: 'PUSH',
params: { id: '42' },
prev: {
id: 'router/HOME',
pathname: '/',
search: '',
queryParams: {},
action: null,
params: {}
prev: null,
}
}