]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix: spread operator compatible
authorwangjiahan <wangjiahan@youzan.com>
Tue, 22 Dec 2020 13:02:58 +0000 (21:02 +0800)
committerwangjiahan <wangjiahan@youzan.com>
Tue, 22 Dec 2020 13:02:58 +0000 (21:02 +0800)
src/devtools.ts
src/utils/index.ts

index 165b14fdfd40ba223b3aee6b8fb804e497aa354c..5fae19444917bf4d2c9af8cb1c33dfba0557285e 100644 (file)
@@ -15,18 +15,18 @@ import { RouteRecordMatcher } from './matcher/pathMatcher'
 import { PathParser } from './matcher/pathParserRanker'
 import { Router } from './router'
 import { RouteLocationNormalized } from './types'
+import { assign, omit } from './utils'
 
 function formatRouteLocation(
   routeLocation: RouteLocationNormalized,
   tooltip?: string
 ) {
-  const copy = {
-    ...routeLocation,
+  const copy = assign({}, routeLocation, {
     // remove variables that can contain vue instances
-    matched: routeLocation.matched.map(
-      ({ instances, children, aliasOf, ...rest }) => rest
+    matched: routeLocation.matched.map(matched =>
+      omit(matched, ['instances', 'children', 'aliasOf'])
     ),
-  }
+  })
 
   return {
     _custom: {
index 35a2b8d06773f36fe46f55c560af9a57b2c909c6..957c8b056bc7e6761e353fcfc2537924a3dd7bdb 100644 (file)
@@ -24,3 +24,20 @@ export function applyToParams(
 }
 
 export let noop = () => {}
+
+export const omit = <T extends Record<string, any>>(
+  object: T,
+  paths: Array<keyof T>
+) => {
+  const result: Record<string, any> = {}
+  for (let key in object) {
+    if (
+      paths.indexOf(key) >= 0 ||
+      !Object.prototype.hasOwnProperty.call(object, key)
+    ) {
+      continue
+    }
+    result[key] = object[key]
+  }
+  return result
+}