]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: rename matchLocation to resolveLocation
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 28 Jun 2019 09:28:18 +0000 (11:28 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 28 Jun 2019 09:28:18 +0000 (11:28 +0200)
src/components/Link.ts
src/index.ts
src/router.ts

index f24373fd72b909f4312932df1d2eb1d6740fc0fe..3c29d523f29732d32287894065db96c132ed7be6 100644 (file)
@@ -26,7 +26,7 @@ const Link: Component = {
       // @ts-ignore
       url = router.history.utils.normalizeLocation(to)
       // TODO: should allow a non matching url to allow dynamic routing to work
-      location = router.matchLocation(url, from)
+      location = router.resolveLocation(url, from)
     } else {
       // named or relative route
       // @ts-ignore
@@ -35,7 +35,7 @@ const Link: Component = {
       )
       const hash = to.hash || ''
       // we need to resolve first
-      location = router.matchLocation({ ...to, query, hash }, from)
+      location = router.resolveLocation({ ...to, query, hash }, from)
       // intentionally drop current query and hash
       // @ts-ignore
       url = router.history.utils.normalizeLocation({
@@ -44,7 +44,7 @@ const Link: Component = {
         ...location,
       })
     }
-    const route = router.matchLocation(url, from)
+    const route = router.resolveLocation(url, from)
 
     // TODO: active classes
     // TODO: handle replace prop
index d974013b777408ba4b8ff0d250d79350a7a19616..5d5afbd39cd1085dd40551a45311780df76915f7 100644 (file)
@@ -4,6 +4,8 @@ import { PluginFunction } from 'vue'
 import View from './components/View'
 import Link from './components/Link'
 
+// TODO: type things
+
 const plugin: PluginFunction<void> = Vue => {
   Vue.mixin({
     beforeCreate() {
index daf6a37a311e7197616f667bb632786c69c5bf06..eb789946f3fc30c30cc3986298629987d4bb9fd3 100644 (file)
@@ -50,7 +50,7 @@ export class Router {
     this.matcher = new RouterMatcher(options.routes)
 
     this.history.listen(async (to, from, info) => {
-      const matchedRoute = this.matchLocation(to, this.currentRoute)
+      const matchedRoute = this.resolveLocation(to, this.currentRoute)
       // console.log({ to, matchedRoute })
 
       const toLocation: RouteLocationNormalized = { ...to, ...matchedRoute }
@@ -109,7 +109,7 @@ export class Router {
   }
 
   // TODO: rename to resolveLocation?
-  matchLocation(
+  resolveLocation(
     location: MatcherLocation & Required<RouteQueryAndHash>,
     currentLocation: RouteLocationNormalized,
     redirectedFrom?: RouteLocationNormalized
@@ -134,7 +134,7 @@ export class Router {
 
       if (typeof redirect === 'string') {
         // match the redirect instead
-        return this.matchLocation(
+        return this.resolveLocation(
           this.history.utils.normalizeLocation(redirect),
           currentLocation,
           normalizedLocation
@@ -143,7 +143,7 @@ export class Router {
         const newLocation = redirect(normalizedLocation)
 
         if (typeof newLocation === 'string') {
-          return this.matchLocation(
+          return this.resolveLocation(
             this.history.utils.normalizeLocation(newLocation),
             currentLocation,
             normalizedLocation
@@ -154,7 +154,7 @@ export class Router {
         // there was a redirect before
         // if (!('path' in newLocation) && !('name' in newLocation)) throw new Error('TODO: redirect canot be relative')
 
-        return this.matchLocation(
+        return this.resolveLocation(
           {
             ...newLocation,
             query: this.history.utils.normalizeQuery(newLocation.query || {}),
@@ -164,7 +164,7 @@ export class Router {
           normalizedLocation
         )
       } else {
-        return this.matchLocation(
+        return this.resolveLocation(
           {
             ...redirect,
             query: this.history.utils.normalizeQuery(redirect.query || {}),
@@ -201,13 +201,13 @@ export class Router {
     if (typeof to === 'string' || 'path' in to) {
       url = this.history.utils.normalizeLocation(to)
       // TODO: should allow a non matching url to allow dynamic routing to work
-      location = this.matchLocation(url, this.currentRoute)
+      location = this.resolveLocation(url, this.currentRoute)
     } else {
       // named or relative route
       const query = to.query ? this.history.utils.normalizeQuery(to.query) : {}
       const hash = to.hash || ''
       // we need to resolve first
-      location = this.matchLocation({ ...to, query, hash }, this.currentRoute)
+      location = this.resolveLocation({ ...to, query, hash }, this.currentRoute)
       // intentionally drop current query and hash
       url = this.history.utils.normalizeLocation({
         query,