]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: use shallowRef
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 24 Apr 2020 16:43:27 +0000 (18:43 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 24 Apr 2020 16:43:27 +0000 (18:43 +0200)
src/router.ts
src/types/index.ts

index 68226e194474664c6ac3344a52cb0da991f6e478..f9004c496235d45334438e1bd4ccafaa8737820b 100644 (file)
@@ -39,7 +39,7 @@ import {
   parseQuery as originalParseQuery,
   stringifyQuery as originalStringifyQuery,
 } from './query'
-import { ref, Ref, markRaw, nextTick, App, warn } from 'vue'
+import { shallowRef, Ref, nextTick, App, warn } from 'vue'
 import { RouteRecord, RouteRecordNormalized } from './matcher/types'
 import { parseURL, stringifyURL, isSameRouteLocation } from './location'
 import { extractComponentsGuards, guardToPromiseFn } from './navigationGuards'
@@ -161,7 +161,7 @@ export function createRouter({
   const beforeGuards = useCallbacks<NavigationGuardWithThis<undefined>>()
   const beforeResolveGuards = useCallbacks<NavigationGuardWithThis<undefined>>()
   const afterGuards = useCallbacks<PostNavigationGuard>()
-  const currentRoute = ref<RouteLocationNormalizedLoaded>(
+  const currentRoute = shallowRef<RouteLocationNormalizedLoaded>(
     START_LOCATION_NORMALIZED
   )
   let pendingLocation: RouteLocation = START_LOCATION_NORMALIZED
@@ -525,7 +525,7 @@ export function createRouter({
     }
 
     // accept current navigation
-    currentRoute.value = markRaw(toLocation)
+    currentRoute.value = toLocation
     // TODO: this doesn't work on first load. Moving it to RouterView could allow automatically handling transitions too maybe
     // TODO: refactor with a state getter
     if (isBrowser) {
index 3943a79166254348849ae45d005c9fd2503ab87f..3a6fe8b47f5e6ba2affb4c3f3343e4cac7299a83 100644 (file)
@@ -1,6 +1,6 @@
 import { LocationQuery, LocationQueryRaw } from '../query'
 import { PathParserOptions } from '../matcher/pathParserRanker'
-import { markRaw, Ref, ComputedRef, ComponentOptions } from 'vue'
+import { Ref, ComputedRef, ComponentOptions } from 'vue'
 import { RouteRecord, RouteRecordNormalized } from '../matcher/types'
 import { HistoryState } from '../history/common'
 
@@ -201,19 +201,17 @@ export type RouteRecordRaw =
   | RouteRecordMultipleViews
   | RouteRecordRedirectRaw
 
-export const START_LOCATION_NORMALIZED: RouteLocationNormalizedLoaded = markRaw(
-  {
-    path: '/',
-    name: undefined,
-    params: {},
-    query: {},
-    hash: '',
-    fullPath: '/',
-    matched: [],
-    meta: {},
-    redirectedFrom: undefined,
-  }
-)
+export const START_LOCATION_NORMALIZED: RouteLocationNormalizedLoaded = {
+  path: '/',
+  name: undefined,
+  params: {},
+  query: {},
+  hash: '',
+  fullPath: '/',
+  matched: [],
+  meta: {},
+  redirectedFrom: undefined,
+}
 
 // make matched non enumerable for easy printing
 // NOTE: commented for tests at RouterView.spec