From 58460bca1fca9f4c48f101b6c295ad9f42ca397a Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 20 Apr 2022 16:16:09 +0200 Subject: [PATCH] feat(router): allow pausing listeners Close #1270 --- src/router.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/router.ts b/src/router.ts index dee1f9b9..fe511b8d 100644 --- a/src/router.ts +++ b/src/router.ts @@ -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, -- 2.47.3