From 3528c64aa969fdce1ab18f2d59f22afa5337121a Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 21 Jan 2020 18:19:10 +0100 Subject: [PATCH] fix: mark currentRoute as non reactive to preserve properties --- src/router.ts | 10 +++++----- src/types/index.ts | 23 +++++++++++++---------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/router.ts b/src/router.ts index 6e7b8693..0d1d2c40 100644 --- a/src/router.ts +++ b/src/router.ts @@ -33,7 +33,7 @@ import { import { extractComponentsGuards, guardToPromiseFn } from './utils' import { encodeParam } from './utils/encoding' import { decode } from './utils/encoding' -import { ref, Ref } from '@vue/reactivity' +import { ref, Ref, markNonReactive } from '@vue/reactivity' type ErrorHandler = (error: any) => any // resolve, reject arguments of Promise constructor @@ -269,7 +269,7 @@ export function createRouter({ else history.push(url) const from = currentRoute.value - currentRoute.value = toLocation + currentRoute.value = markNonReactive(toLocation) updateReactiveRoute() handleScroll(toLocation, from).catch(err => triggerError(err, false)) @@ -376,10 +376,10 @@ export function createRouter({ } // accept current navigation - currentRoute.value = { + currentRoute.value = markNonReactive({ ...to, ...matchedRoute, - } + }) updateReactiveRoute() // TODO: refactor with a state getter // const { scroll } = history.state @@ -532,7 +532,7 @@ export function createRouter({ // already contains current location const from = currentRoute.value - currentRoute.value = toLocation + currentRoute.value = markNonReactive(toLocation) updateReactiveRoute() // navigation is confirmed, call afterGuards diff --git a/src/types/index.ts b/src/types/index.ts index 44091c64..fad29513 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,5 +1,6 @@ import { HistoryQuery, RawHistoryQuery } from '../history/common' import { PathParserOptions } from '../matcher/path-parser-ranker' +import { markNonReactive } from '@vue/reactivity' // type Component = ComponentOptions | typeof Vue | AsyncComponent @@ -135,16 +136,18 @@ export type RouteRecord = | RouteRecordRedirect // TODO: this should probably be generate by ensureLocation -export const START_LOCATION_NORMALIZED: RouteLocationNormalized = { - path: '/', - name: undefined, - params: {}, - query: {}, - hash: '', - fullPath: '/', - matched: [], - meta: {}, -} +export const START_LOCATION_NORMALIZED: RouteLocationNormalized = markNonReactive( + { + path: '/', + name: undefined, + params: {}, + query: {}, + hash: '', + fullPath: '/', + matched: [], + meta: {}, + } +) // make matched non enumerable for easy printing Object.defineProperty(START_LOCATION_NORMALIZED, 'matched', { -- 2.47.3