From: Eduardo San Martin Morote Date: Wed, 20 Apr 2022 14:16:09 +0000 (+0200) Subject: feat(router): allow pausing listeners X-Git-Tag: v4.1.0~134 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=58460bca1fca9f4c48f101b6c295ad9f42ca397a;p=thirdparty%2Fvuejs%2Frouter.git feat(router): allow pausing listeners Close #1270 --- 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,