A simple middleware-style router for isomorphic JavaScript web apps
null
(BREAKING CHANGE #140)Migration from v4 to v5:
resolveRoute
option for custom route handling logic then you need to return undefined
instead of null
in cases when a route should not matchnull
are working as you expect, child routes are no longer executed in this case, use undefined
instead if necessarycontext.keys
when they preserved from parent routes (i.e. keys order is the same as they appear in a url) (#129)const routes = [
{ path: '/posts', ... }, // matches both "/posts" and "/posts/"
{ path: '/posts/', ... }, // matches only "/posts/"
];
const router = new UniversalRouter({
name: 'page',
path: ['/one', '/two', /RegExp/], // only first path is used for url generation
});
const url = generateUrls(router);
url('page'); // => /one
const router = new UniversalRouter({
path: ['/one/:parameter', '/two/:parameter'],
action: context => context.params,
});
router.resolve('/one/a'); // => { parameter: 'a' }
router.resolve('/two/b'); // => { parameter: 'b' }
router.resolve({ path })
to router.resolve({ pathname })
(BREAKING CHANGE #114)context.url
to context.pathname
(BREAKING CHANGE #114)pretty
option from generateUrls(router, options)
function in favor of new encode
option (BREAKING CHANGE #111)/test/
is now treated as /test/
instead of /test
when matching)*
) - use parameters instead ((.*)
)encode
option to generateUrls(router, options)
function for pretty encoding (e.g. pass your own implementation) (#111)context.keys
values from the parent route (#111)context.params
and queryParams
from Object (e.g. params.hasOwnProperty()
won't throw an exception anymore) (#111)Migration from v3 to v4:
router.resolve({ path, ... })
to router.resolve({ pathname, ... })
path: '/posts/:uri/'
=> path: '/posts/:uri'
path: '/posts/'
=> path: '/posts'
path: '/'
=> path: ''
path: '*'
with path: '(.*)'
if any.js
files to include .mjs
extension, i.e.
test: /\.js$/
=> test: /\.m?js$/
stringifyQueryParams
option to generateUrls(router, options)
to generate URL with query string from unknown route params (#93)