]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
feat(router): allow pausing listeners
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 20 Apr 2022 14:16:09 +0000 (16:16 +0200)
committerEduardo San Martin Morote <posva@users.noreply.github.com>
Thu, 30 Jun 2022 07:59:00 +0000 (09:59 +0200)
Close #1270

src/router.ts

index dee1f9b9df4af4e993b91a4768d35395ff64a253..fe511b8da56943b39bfee84b200d2e6ff862aa9b 100644 (file)
@@ -197,6 +197,11 @@ export interface Router {
    */
   readonly options: RouterOptions
 
+  /**
+   * Allows turning off the listening of history events. This is a low level api for micro-frontends.
+   */
+  listening: boolean
+
   /**
    * Add a new {@link RouteRecordRaw route record} as the child of an existing route.
    *
@@ -944,6 +949,7 @@ export function createRouter(options: RouterOptions): Router {
     // avoid setting up listeners twice due to an invalid first navigation
     if (removeHistoryListener) return
     removeHistoryListener = routerHistory.listen((to, _from, info) => {
+      if (!router.listening) return
       // cannot be a redirect route because it was in history
       const toLocation = resolve(to) as RouteLocationNormalized
 
@@ -1150,6 +1156,7 @@ export function createRouter(options: RouterOptions): Router {
 
   const router: Router = {
     currentRoute,
+    listening: true,
 
     addRoute,
     removeRoute,