With the v2 major release, Vaadin Router was entirely ported to TypeScript. We removed outdated code and features targeting MSIE 11, bower, and HTML imports, and updated the libraries and build tools we use. In addition, we introduced generic parameters on the router core types, which facilitates extendibility of the route definition on the user end.
New Features
- Generic route type support. The
Router
class supports route object extensions provided with a generic argument. This allows adding custom metadata directly on the route object with keeping consistent types:/** * Custom route metadata. */ type RouteMeta = Readonly<{ title: string; }>; const router = new Router<RouteMeta>(document.body); router.setRoutes([ { path: '', component: 'page-index', title: 'Index page', }, ]);
Breaking Changes
- Removing support for MS Internet Explorer.
- Support for
bundle
route key was removed. Now that using ES modules is common, for lazy loading of views use dynamic import from theaction
callback. - The
Router
namespace export was removed. For referencing router types, either refer to exports directly, or use ES module namespace import:import type * as RouterTypes from '@vaadin/router';
- The
path-to-regexp
library was updated to v6.3.0. This update brought some behavior altering changes affecting route parameter parsing and matching. See to the library README for the supported patterns. - Some TypeScript interfaces of the router library were changed with introducing generic support:
- The
Context
type was replaced with theRouteContext
generic type. - The
ComponentResult
type is replaced with the standardHTMLElement
type. - The
AfterEnterObserver
,AfterLeaveObserver
,BeforeEnterObserver
,BeforeLeaveObserver
interfaces were combined into the single genericWebComponentInterface
with multiple optional user callbacks. - The
ActionFn
function type has no direct alternative yet. Use the key of theRoute
type:NonNullable<Route["action"]>
.
- The
Known Limitations
The following known issues of the router v2.0.0 release will be addressed in the next v2.0.1 release:
- Type compatibility with the Router v1 is lacking due to missing type definitions for Router v1 types:
Context
,ComponentResult
,AfterEnterObserver
,AfterLeaveObserver
,BeforeEnterObserver
,BeforeLeaveObserver
observer interfaces. - The Router requires
ES2022
target setting in TypeScript due to relying on theErrorOptions
type, see #897
In addition, the live router demos are not available yet. We're currently working on porting them from HTML imports and Polymer toolset to ES modules, TypeScript and Vite.
Notable Changes since v1.7.5
- fix: move version output from preversion to version script by @platosha in #546
- chore!: update path-to-regexp by @abdonrd in #351
- feat!: Drop support for route.bundle by @abdonrd in #464
- fix: failing tests after path-to-regexp 6.2.0 update by @vlukashov in #549
- fix: scroll to top on click event by @haijian-vaadin in #547
- fix: avoid URL-confusing default pathname in baseUrl by @platosha in #565
- fix: removeDomNodes with HTMLCollection by @joheriks in #583
- fix: skip undefined base argument in URL constructor by @platosha in #584
- feat: add searchParams for RouterLocation by @haijian-vaadin in #582
- fix: npm install with npm 7 by @Haprog in #592
- docs: fix demo and API docs links in readme by @Haprog in #606
- chore: set type to module in package.json by @vursen in #721
- docs: typo in URL Generation demo by @pdurbin in #800
- chore: fix build for "type": "module" by @platosha in #833
- refactor!: move Router fully to TypeScript by @Lodin in #886
- chore: bump version by @platosha in #887
- fix: support WCs with result property by @platosha in #889
- fix: Router#resolve typings by @Lodin in #891
New Contributors
- @Haprog made their first contribution in #548
- @joheriks made their first contribution in #583
- @vursen made their first contribution in #721
- @pdurbin made their first contribution in #800
- @Lodin made their first contribution in #886
Full Changelog: v1.7.5...v2.0.0