Skip to content

v2.0.0

Latest
Compare
Choose a tag to compare
@ZheSun88 ZheSun88 released this 08 Nov 09:35
7e87b3b

API documentation

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 the action 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 the RouteContext generic type.
    • The ComponentResult type is replaced with the standard HTMLElement type.
    • The AfterEnterObserver, AfterLeaveObserver, BeforeEnterObserver, BeforeLeaveObserver interfaces were combined into the single generic WebComponentInterface with multiple optional user callbacks.
    • The ActionFn function type has no direct alternative yet. Use the key of the Route type: NonNullable<Route["action"]>.

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 the ErrorOptions 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

New Contributors

Full Changelog: v1.7.5...v2.0.0