Skip to content

Update the way a navigation route is registered #319

@delawski

Description

@delawski

After updating PWA plugin from version 0.3 to 0.4 or 0.5, the following error is thrown in the console during a SW installation:

wp_service_worker=1:411 Uncaught TypeError: wp.serviceWorker.routing.registerNavigationRoute is not a function
    at ?wp_service_worker=1:411
    at ?wp_service_worker=1:477

It seems that the way the navigation route is registered is no longer supported in Workbox 5.

The SW is successfully installed with the following change:

- wp.serviceWorker.routing.registerNavigationRoute(
-   navigationRouteEntry.url,
-   {
-     denylist,
-   }
- );
+ wp.serviceWorker.routing.registerRoute(
+   new wp.serviceWorker.routing.NavigationRoute(
+     wp.serviceWorker.precaching.createHandlerBoundToURL(
+      navigationRouteEntry.url
+     ),
+     {
+       denylist,
+     }
+   )
+ );

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions