This is a stub types definition for Universal Router (https://github.com/kriasoft/universal-router).
Universal Router provides its own type definitions, so you don't need @types/universal-router installed!
This is a stub types definition. universal-router provides its own type definitions, so you do not need this installed.
Stub TypeScript definitions entry for Universal Router, which provides its own types definitions
This is a stub types definition for Universal Router (https://github.com/kriasoft/universal-router).
Universal Router provides its own type definitions, so you don't need @types/universal-router installed!
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
- const pathToRegexp = require('path-to-regexp')
+ import * as pathToRegexp from 'universal-router/path-to-regexp'
- import generateUrls from 'universal-router/generateUrls'
+ import generateUrls from 'universal-router/generate-urls'
noPropertyAccessFromIndexSignature
and noUncheckedIndexedAccess
checks (#216)uniqueRouteNameSep
option to generateUrls(router, options)
to allow non-unique route names
among different branches of nested routes and access them by uniquely generated name
(#194)router.resolve()
and context.next()
always return a promise now
(#187)context.keys
(BREAKING CHANGE)generateUrls
compatible with UniversalRouterSync
(#172)context.next()
to throw Route not found
instead of TypeError
(#169)Migration from v6 to v7:
error.context
or error.code
you still can access them
using errorHandler
option:errorHandler(error, context) {
const code = error.status || 500
console.log(error, context, code)
}
Migration from v5 to v6:
error.code
instead of error.status
or error.statusCode
for error handling.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 casecontext.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
Support for using the same param name in array of paths (#122)
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)context.next()
for multiple nested routes
(#91)pretty
option for generateUrls(router, options)
to prettier encoding of URI path segments
(#88)Update Router API (BREAKING CHANGE)
import Router from 'universal-router'
const router = new Router(routes, options)
router.resolve({ path, ...context }) // => Promise<any>
// previously
import { resolve } from 'universal-router'
resolve(routes, { path, ...context }) // => Promise<any>
See #83 for more info and examples
context.next()
now iterates only child routes by default (BREAKING CHANGE)
use context.next(true)
to iterate through the all remaining routes
babel-runtime
dependency to decrease library size (BREAKING CHANGE)import generateUrls from 'universal-router/generate-urls'
const url = generateUrls(router)
url(routeName, params) // => String
context.route.parent
to iteratenew Router(routes, { resolveRoute: customResolveRouteFn })
new Router(routes, { baseUrl: '/base' })
new Router(routes, { context: { ... } })
matchRoute
function without usage of
generators
to decrease amount of necessary polyfillscontext.url
with the original url passed to resolve
methodcontext
property to Route not found
errorcontext.params
values from the parent route (#57)context.end()
method (#60)match
alias for resolve
function (#59)null
the same way as undefined
(#51)null
instead of undefined
to signal no match (#51)context.next()
across multiple routes (#49)match()
to resolve()
. E.g. import { resovle } from 'universal-router'
children
property/products/:id?
(#27)matchRoute()
yielding the same route twice when it matches to both full and base URLsmatch(routes, { path, ...context)
now throws an error if a matching route was not found (BREAKING CHANGE)/error
, it will be used for error handling by conventionRouter
class and router.dispatch()
method in favor of
match(routes, { path, ...context })
, where routes
is just a plain JavaScript objects containing
the list of routes (BREAKING CHANGE)context.end()
method to be used from inside route actionsreact-routing
to universal-router
(BREAKING CHANGE)router.on(path, ...actions)
in favor of router.route(path, ...actions)
(BREAKING CHANGE)new Router(on => { ... })
initialization option in favor of new Router(routes)
(BREAKING CHANGE)docs/assets
.package.json
, update Babel and its plug-ins to the latest versionsbabel-runtime
package instead of an inline runtime